Galebickosikasa

Untitled

Nov 1st, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.94 KB | None | 0 0
  1. package com.example.myapplication;
  2.  
  3. import androidx.appcompat.app.AppCompatActivity;
  4.  
  5. import android.os.Bundle;
  6. import android.util.Log;
  7. import android.view.View;
  8. import android.widget.EditText;
  9. import android.widget.TextView;
  10. import android.widget.Toast;
  11.  
  12. import static java.lang.Math.sqrt;
  13.  
  14. public class MainActivity extends AppCompatActivity {
  15.  
  16.     @Override
  17.     protected void onCreate(Bundle savedInstanceState) {
  18.         super.onCreate(savedInstanceState);
  19.         setContentView(R.layout.activity_main);
  20.     }
  21.  
  22.     public void calc(View v) {
  23.         TextView tv = findViewById(R.id.textView4);
  24.         EditText object_a = findViewById(R.id.editText);
  25.         if (object_a.length() == 0) {
  26.             tv.setText("Try again)");
  27.             return;
  28.         }
  29.         String text_a = object_a.getText().toString();
  30.         double a = Integer.parseInt(text_a);
  31.         EditText object_b = findViewById(R.id.editText2);
  32.         if (object_b.length() == 0) {
  33.             tv.setText("Try again)");
  34.             return;
  35.         }
  36.         String text_b = object_b.getText().toString();
  37.         double b = Integer.parseInt(text_b);
  38.         EditText object_c = findViewById(R.id.editText3);
  39.         if (object_c.length() == 0) {
  40.             tv.setText("Try again)");
  41.             return;
  42.         }
  43.         String text_c = object_c.getText().toString();
  44.         double c = Integer.parseInt(text_c);
  45.         double D = b * b - 4 * a * c;
  46.         System.out.println(D);
  47.         Toast.makeText(this, "D = " + D, Toast.LENGTH_LONG).show();
  48. //        Log.e("D = ", "" + D);
  49.         if (D < 0) {
  50.             // empty set
  51.             tv.setText("Empty set LOL");
  52.         } else if (D == 0) {
  53.             double x = -b / 2 * a;
  54.             tv.setText("" + x);
  55.         } else{
  56.             double x1 = (-b + sqrt(D)) / 2 * a;
  57.             double x2 = (-b - sqrt(D)) / 2 * a;
  58.             tv.setText("" + x1 + "   " + x2);
  59.         }
  60.  
  61.     }
  62.  
  63. }
Add Comment
Please, Sign In to add comment