-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainActivity.java
55 lines (38 loc) · 1.4 KB
/
MainActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.example.thegreatcafe;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import java.text.NumberFormat;
public class MainActivity extends AppCompatActivity {
int quant=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); }
public void incrementbyone(View view){
quant=quant+1;
display1(quant);
// This is used when you want that just on increment it automatically update the price without pressing the calculate button
// int amount=5;
// display2(amount*quant);
}
public void decrement(View view){
quant=quant-1;
display1(quant);
// int amount=5;
// display2(amount*quant);
}
public void calculateTheAmount(View view){
int amount=5;
display2(quant*amount);
}
private void display1(int number){
TextView textView6=(TextView) findViewById(R.id.textView6);
textView6.setText(""+number);}
private void display2(int number) {
TextView textView3 = (TextView) findViewById(R.id.textView3);
textView3.setText(NumberFormat.getCurrencyInstance().format(number));}
}