-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtotalSales.java
More file actions
136 lines (110 loc) · 3.64 KB
/
totalSales.java
File metadata and controls
136 lines (110 loc) · 3.64 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
* Filename: totalSales.java
* Author: Justin Lee
* Date: 11 December 2019
* Description: This will hold the price of all the objects
* and calculate the sales tax based ont hat
* correctly accounting for whether the item
* is imported or not
*/
import java.util.*;
import java.io.*;
public class totalSales{
//because we calculate tax on domestic and import separately
private double domesticTotal;
private double importTotal;
private double edomesticTotal;
private double eimportTotal;
//default constructor here
public totalSales(){
domesticTotal = 0.0;
importTotal = 0.0;
edomesticTotal = 0.0;
eimportTotal = 0.0;
}
public totalSales(double dt, double it){
this.domesticTotal = dt;
this.importTotal = it;
edomesticTotal = 0.0;
eimportTotal = 0.0;
}
public void clear(){
domesticTotal = 0.0;
importTotal = 0.0;
edomesticTotal = 0.0;
eimportTotal = 0.0;
}
//setters
public void setdomesticTotal(double dt){
this.domesticTotal = dt;
}
public void setimportTotal(double it){
this.importTotal = it;
}
public void seteimportTotal(double it){
this.eimportTotal = it;
}
public void setedomesticTotal(double it){
this.edomesticTotal = it;
}
//methods to increment the total amounts
public void incdomesticTotal(double dt){
this.domesticTotal += dt;
}
public void incimportTotal(double it){
this.importTotal += it;
}
public void incedomesticTotal(double dt){
this.edomesticTotal += dt;
}
public void inceimportTotal(double it){
this.eimportTotal += it;
}
//in this method we have to check to see if the exempt variable
//has been set in the parameter salesobject
//potentially we can go ahead and have 4 categories for sales
//imported / not imported and
//exempt / not exempt and the two categories will combine 2x2 = 4
public void incfromsales(salesObject saleso){
if(saleso.getImport()){
if(saleso.getExempt()){
this.inceimportTotal(saleso.getPrice());
}
else{ //i.e not exempt
this.incimportTotal(saleso.getPrice());
}
}
else{
if(saleso.getExempt()){
this.incedomesticTotal(saleso.getPrice());
}
else{
this.incdomesticTotal(saleso.getPrice());
}
}
}
//here we are calculating the tax and then we are going to print it
//we can unit test this function
public double calculateTax(){
double taxfromdomestic = domesticTotal * 0.10;
double taxfromimport = importTotal * 0.15;
double taxfromeimport = eimportTotal * 0.05;
double totaltax = taxfromdomestic + taxfromimport + taxfromeimport;
//totaltax now needs to be rounded to the nearest 0.05 decimal spot.
//according to the specifications of the assignment, we are going to round up
int twodecint = (int)(totaltax * 10000); //we round to 4 decimal places to get
//better accuracy when rounding
if( (twodecint % 500) != 0) {
twodecint += (500 - (twodecint %500 ));
}
totaltax = (double)(twodecint / 10000.0);
//should be rounded now... we can unit test here
return totaltax;
}
public void taxandtotalprinter(){
double salestax = this.calculateTax();
double total = domesticTotal + importTotal + edomesticTotal + eimportTotal + salestax;
System.out.printf("Sales Taxes: %.2f\n", salestax);
System.out.printf("Total: %.2f\n\n", total);
}
}