Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.shishu;
- import androidx.appcompat.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TextView;
- public class MainActivity extends AppCompatActivity {
- EditText e1;
- TextView t1;
- Button b1;
- int dis;
- float total;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- e1 =(EditText)findViewById(R.id.e1);
- t1 =(TextView)findViewById(R.id.t1);
- b1 = (Button)findViewById(R.id.b1);
- b1.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- dis = Integer.parseInt(e1.getText().toString());
- if(dis <= 50) {
- total = dis*1;
- t1.setText(String.valueOf(total));
- }
- if(dis>=50 && dis<=150){
- total=50+(dis-50)*2;
- t1.setText(String.valueOf(total));
- }
- if(dis>=151 && dis<=2550){
- total=50+200+(dis-150)*3;
- t1.setText(String.valueOf(total));
- }
- if(dis>250){
- total=50+200+300+(dis-250)*4;
- t1.setText(String.valueOf(total));
- }
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement