2017-02-20 90 views
-1

讓我們來寫你的名字和GPA,如果你的GPA是3或以上,它應該說它會接受你的工作,如果不是,那麼它不會。所以這一切似乎都在工作,但它沒有註冊號碼?就像我說的那個數字一樣,說你不接受這份工作。我不清楚我必須輸入什麼代碼來確保它知道輸入是一個數字/它知道數字是否大於3.這是我的代碼。GPA輸入混淆

public class MainActivity extends AppCompatActivity{ 
    @Override 
    protected void onCreate(Bundle savedInstanceState){ 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     //references to two objects: EditText and Button 
     final EditText inputName = (EditText) findViewById(R.id.nameET); 
     Button clickB = (Button) findViewById(R.id.showBTN); 
     final EditText inputGpa = (EditText) findViewById(gpaET); 
     final TextView outputa = (TextView) findViewById(messageTV); 

     final int gpaET = 0; 

     //setting up a listener to the clickB 
     clickB.setOnClickListener(new View.OnClickListener(){ 
      @Override 
      public void onClick(View v){ 
       //reading the user name input 
       String userName = inputName.getText().toString(); 

       double n1 = Double.valueOf(inputGpa.getText().toString()); 

       if(gpaET >= 3) { 
        outputa.setText("Hello, " + userName + "With your current gpa, you will be considered for the job."); 
       }else { 
        outputa.setText("Hello, " + userName + "With your current gpa, you will not be considered for the job, sorry."); 
       } 
      }}); 
    }} 
+0

您gpaET設置爲0。 – Serafins

回答

1

你的問題是,你是不是比較輸入,而是你的不變,試試這個:

public class MainActivity extends AppCompatActivity 
{ 
    @Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     //references to two objects: EditText and Button 
     final EditText inputName = (EditText) findViewById(R.id.nameET); 
     Button clickB = (Button) findViewById(R.id.showBTN); 
     final EditText inputGpa = (EditText) findViewById(gpaET); 
     final TextView outputa = (TextView) findViewById(messageTV); 


     //setting up a listener to the clickB 
     clickB.setOnClickListener(new View.OnClickListener() 
     { 
      @Override 
      public void onClick(View v) 
      { 
       //reading the user name input 
       String userName = inputName.getText().toString(); 

       //This is where you get the numeric input 
       double n1 = Double.valueOf(inputGpa.getText().toString()); 



       if(n1 >= 3) { 
        outputa.setText("Hello, " + userName + "With your current gpa, you will be considered for the job."); 
       } 

       else { 
        outputa.setText("Hello, " + userName + "With your current gpa, you will not be considered for the job, sorry."); 
       } 


      } 

     }); 
    } 
}