You found an exciting summer job for five weeks. It pays a set amount per hour (
ID: 3663379 • Letter: Y
Question
You found an exciting summer job for five weeks. It pays a set amount per hour (for example, $15.50). Suppose that the total tax you pay on your summer job income is 14%. After paying the taxes, you spend 10% of your net income (income after taxes) to buy new clothes and other accessories for the next school year and 1% to buy school supplies. After buying clothes and school supplies, you use 25% of the remaining money to buy savings bonds. For each dollar you spend to buy savings bonds (rounded down), your parents spend $0.50 to buy additional savings bonds for you. Write a program that prompts the user to enter the pay rate for an hour and the number of hours you worked each week. The program then outputs the following:
Your income before and after taxes from your summer job.
The money you spend on clothes and other accessories.
The money you spend on school supplies.
The money you spend to buy savings bonds.
The money your parents spend to buy additional savings bonds for you.
The remaining income after expenses and investments.
create a small test plan for your finished product with at least 4 cases.
Explanation / Answer
Java Program:
package chegg;
import java.util.Scanner;
class FinancialPlan{
public int workWeeks = 5;
public double tax = 14;
public double clothesShare = 10;
public double suppliesShare = 1;
public double savingBondShare= 25;
public double parentsBonds = 0.5;
}
class WorkPlan {
public double hoursPerWeek;
public double perHourCost;
}
class FinalAmounts {
private WorkPlan workPlan;
private FinancialPlan financialPlan;
public double incomeBeforeTax;
public double incomeAfterTax;
public double clothesAccessories;
public double schoolSupplies;
public double mySavings;
public double parentsSavings;
public double balanceAmount;
public FinalAmounts(FinancialPlan financialPlan, WorkPlan workPlan) {
this.financialPlan = financialPlan;
this.workPlan = workPlan;
calculateNetSalary();
calculateClothesAndSupplies();
calculateMySavings();
calculateParentsSavings();
}
private void calculateNetSalary() {
this.incomeBeforeTax = financialPlan.workWeeks * workPlan.perHourCost * workPlan.hoursPerWeek;
double totalTax = financialPlan.tax * this.incomeBeforeTax / 100.0;
this.incomeAfterTax = this.incomeBeforeTax - totalTax;
this.balanceAmount = this.incomeAfterTax;
}
private void calculateClothesAndSupplies() {
this.clothesAccessories = this.balanceAmount * financialPlan.clothesShare /100.0;
this.schoolSupplies = this.balanceAmount * financialPlan.suppliesShare /100.0;
this.balanceAmount = this.balanceAmount - this.clothesAccessories - this.schoolSupplies;
}
private void calculateMySavings() {
this.mySavings = this.balanceAmount * financialPlan.savingBondShare / 100.0;
this.balanceAmount = this.balanceAmount - this.mySavings;
}
private void calculateParentsSavings() {
this.parentsSavings = Math.round(this.mySavings)/2; //since $0.5 for every dollar i saved i.e., its half of what i saved
}
public void printResult() {
System.out.println("Income before tax: " + this.incomeBeforeTax);
System.out.println("Income after tax: " + this.incomeAfterTax);
System.out.println("Clothes and accessories: " + this.clothesAccessories);
System.out.println("School supplies: " + this.schoolSupplies);
System.out.println("My savings bonds: " + this.mySavings);
System.out.println("My parents savings bonds: " + this.parentsSavings);
System.out.println("Balance amount: " + this.balanceAmount);
}
}
public class Savings {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
WorkPlan workPlan = new WorkPlan();
System.out.print("Enter the pay rate per hour: ");
workPlan.perHourCost = s.nextDouble();
System.out.print("Enter no of hours per week: ");
workPlan.hoursPerWeek = s.nextDouble();
FinancialPlan financialPlan = new FinancialPlan();
FinalAmounts amounts = new FinalAmounts(financialPlan, workPlan);
amounts.printResult();
s.close();
}
}
Results:
Case1:
Enter the pay rate per hour: 1
Enter no of hours per week: 15.5
Income before tax: 77.5
Income after tax: 66.65
Clothes and accessories: 6.665
School supplies: 0.6665000000000001
My savings bonds: 14.829625
My parents savings bonds: 7.0
Balance amount: 44.48887500000001
Case 2:
Enter the pay rate per hour: 5
Enter no of hours per week: 20
Income before tax: 500.0
Income after tax: 430.0
Clothes and accessories: 43.0
School supplies: 4.3
My savings bonds: 95.675
My parents savings bonds: 48.0
Balance amount: 287.025
Case 3:
Enter the pay rate per hour: 3
Enter no of hours per week: 30
Income before tax: 450.0
Income after tax: 387.0
Clothes and accessories: 38.7
School supplies: 3.87
My savings bonds: 86.1075
My parents savings bonds: 43.0
Balance amount: 258.3225
Case 4:
Enter the pay rate per hour: 12
Enter no of hours per week: 15
Income before tax: 900.0
Income after tax: 774.0
Clothes and accessories: 77.4
School supplies: 7.74
My savings bonds: 172.215
My parents savings bonds: 86.0
Balance amount: 516.645
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.