Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. package my.project;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.widget.EditText;
  7. import android.widget.Button;
  8. import android.widget.TextView;
  9. import java.lang.String;
  10. import java.util.regex.*;
  11.  
  12. public class ComplexConverter extends Activity {
  13.     private ComplexA complexA;
  14.     private ComplexE complexE;
  15.     private Pattern p;
  16.     private Matcher m;
  17.     private double a;
  18.    
  19.     private boolean isAlg(String str) {
  20.         p = Pattern.compile("(\\d+)[+-]i(\\d+)",
  21.         Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE);
  22.         m = p.matcher(str);
  23.        
  24.         a = Double.parseDouble(m.group(1));
  25.  
  26.         return m.matches();
  27.     }
  28.    
  29.     @Override
  30.     public void onCreate(Bundle savedInstanceState) {
  31.         super.onCreate(savedInstanceState);
  32.         setContentView(R.layout.main);
  33.        
  34.         complexA = new ComplexA();
  35.         complexE = new ComplexE();
  36.        
  37.         final EditText edit = (EditText) findViewById(R.id.edit);
  38.         Button button = (Button) findViewById(R.id.button);
  39.         final TextView text = (TextView) findViewById(R.id.text);
  40.        
  41.        
  42.        
  43.        
  44.         button.setOnClickListener(new View.OnClickListener() {
  45.             public void onClick(View v) {
  46.                 if (isAlg(edit.getText().toString())) {
  47.                     text.setText(Double.toString(a));  
  48.                 }
  49.             }
  50.         });  
  51.    
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement