-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathMathCalc.java
More file actions
37 lines (29 loc) · 1.31 KB
/
MathCalc.java
File metadata and controls
37 lines (29 loc) · 1.31 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
package org.codedifferently;
import java.util.Random;
public class MathCalc {
//helper class to generate a random number given a lowerBound and upperBound
public int generateRandomNumber(int lowerBound, int upperBound) {
Random random = new Random();
return random.nextInt((upperBound - lowerBound) + 1) + lowerBound;
}
//generates taxRate by picking a random number and converting the % to decimal.
public double generateTaxRate() {
return (generateRandomNumber(1,20)) * 0.01;
}
//calculates the final total by adding taxes and subtracting discounts.
public double calculateFinalTotal(double subTotal, double taxRate, double discountRate) {
return Math.round(subTotal + (subTotal * taxRate) - (subTotal * discountRate));
}
//Calculates remaining budget by subtracting the two arguments and rounding.
public double calculateRemainingBudget(double budget, double finalTotal) {
return Math.round(budget - finalTotal);
}
//Calculates the absolute value.
public double calculateAbsoluteValue(double num) {
return Math.abs(num);
}
//Generates couponDiscount by generating a random number, then converting the % to decimal.
public double generateCouponDiscount() {
return generateRandomNumber(1,50) * 0.01;
}
}