Advertisement
Shishu

JAVA file for an fair a trip app

Dec 20th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.49 KB | None | 0 0
  1. package com.example.shishu;
  2.  
  3. import androidx.appcompat.app.AppCompatActivity;
  4.  
  5. import android.os.Bundle;
  6. import android.view.View;
  7. import android.widget.Button;
  8. import android.widget.EditText;
  9. import android.widget.TextView;
  10.  
  11. public class MainActivity extends AppCompatActivity {
  12. EditText e1;
  13. TextView t1;
  14. Button b1;
  15. int dis;
  16. float total;
  17.     @Override
  18.     protected void onCreate(Bundle savedInstanceState) {
  19.         super.onCreate(savedInstanceState);
  20.         setContentView(R.layout.activity_main);
  21.  
  22.         e1 =(EditText)findViewById(R.id.e1);
  23.         t1 =(TextView)findViewById(R.id.t1);
  24.         b1 = (Button)findViewById(R.id.b1);
  25.  
  26.         b1.setOnClickListener(new View.OnClickListener() {
  27.             @Override
  28.             public void onClick(View v) {
  29.                 dis = Integer.parseInt(e1.getText().toString());
  30.  
  31.                 if(dis <= 50) {
  32.                     total = dis*1;
  33.                     t1.setText(String.valueOf(total));
  34.                 }
  35.  
  36.  
  37.                 if(dis>=50 && dis<=150){
  38.                     total=50+(dis-50)*2;
  39.                     t1.setText(String.valueOf(total));
  40.                 }
  41.                 if(dis>=151 && dis<=2550){
  42.                     total=50+200+(dis-150)*3;
  43.                     t1.setText(String.valueOf(total));
  44.                 }
  45.                 if(dis>250){
  46.                     total=50+200+300+(dis-250)*4;
  47.                     t1.setText(String.valueOf(total));
  48.                 }
  49.             }
  50.         });
  51.  
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement