-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaxTip.java
More file actions
72 lines (53 loc) · 1.93 KB
/
Copy pathTaxTip.java
File metadata and controls
72 lines (53 loc) · 1.93 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.example.receiptsjava;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import java.util.HashMap;
public class TaxTip extends AppCompatActivity {
double taxRate;
double tipPercentage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tax_tip);
Intent i = getIntent();
taxRate = i.getDoubleExtra("tax", 0);
tipPercentage = i.getDoubleExtra("tip", 0);
}
HashMap<String, Double> list = new HashMap<>();
double total = 0.0;
public void enter (View v) {
TextView n = findViewById(R.id.Name);
TextView p = findViewById(R.id.Price);
String name = n.getText().toString();
Double price = Double.parseDouble(p.getText().toString());
total = total + price;
list.put(name, price);
Log.d(name, list.get(name).toString());
n.setText("");
p.setText("");
}
public HashMap<String, Double> totals
(View v) {
double tip = total * tipPercentage;
HashMap<String, Double> ans = new HashMap<>();
for (String person: list.keySet()) {
double personalTotal = list.get(person);
double tax = personalTotal*taxRate;
double portion = list.get(person)/total;
double personalTip = portion*tip;
personalTotal = personalTotal + tax + personalTip;
ans.put(person, personalTotal);
}
for (String person : ans.keySet()) {
Log.d("Name:", ans.get(person).toString());
}
Intent i = new Intent(this, Results.class);
i.putExtra("results", ans);
startActivity(i);
return ans;
}
}