Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Calculate savings using methods. This assignment builds on Assignment #2. Java T

ID: 3588684 • Letter: C

Question

Calculate savings using methods. This assignment builds on Assignment #2.

Java Topics methods, if statements, calculating with percentages.

References   Textbook – use the index for relevant topics.

Specification

This program is an upgrade to Programming Assignment #2 to use methods. We will discuss a revisit of Assignment #1, Interactive Average with Methods, as a model.

Write a Java program and methods in the order listed below.

Declare the variables as type double for the gross pay, savings rate, IRA investment rate, savings amount, IRA investment amount and the total of the two amounts inside the main method and use them as appropriate when you call methods.

Call a void method that will output an explanation of what the program does. The explanation is this statement:

            This program calculates savings amounts using methods.

2.   Input these three numbers: gross pay, savings rate and IRA investment rate. Use one method to read and return a value so you will call this method three times. When a number is input, ensure it is greater than 0. Note: use the System.out.print style of Assignment #2 to prompt for input, not JOptionPane as in Assignment #3. Use the prompts exactly as shown below in step 4. If an input value is 0 or less, use this message:

            Please enter a value greater than 0.

      and prompt again for the value you are requesting.

Calculate the savings amount and IRA investment amounts using one method for both calculations. The method will have two parameters, the gross pay and the respective percentage rate. In the main program, use a third variable to calculate the total of these two amounts.

Use a void method to output, with the messages below: the three values that were inputted, the savings amount, IRA investment amount, and the total of the two amounts.

      Note that this method requires six parameters. Output all decimal results to one or two places, depending on whether the result is a rate or a dollar amount, respectively. Using a gross pay of $10,000, a savings rate of 10% and an IRA rate of 5%, the messages are:

   Enter the gross pay: 10000

   Enter the savings rate %: 10

   Enter the IRA rate: 5

   Gross pay: 10,000.00

   Savings rate: 10.0%

   Savings amount: 1,000.00

   IRA rate: 5.0%

   IRA amount: 500.00

   Total of amounts: 1,500.00

As before, include comments – programmer identification, assignment number, section, purpose, explanation for all variables, parameters, and methods, and the vocabulary word and quote. See the documentation standards.

Explanation / Answer

package org.students;

import java.text.DecimalFormat;
import java.util.Scanner;

public class CalculateSavings {

public static void main(String[] args) {
double grossPay, savingsRate, IRARate, savingsAmount, IRAAmount, total;

//calling the method
programReq();

//Getting the inputs entered by the user
System.out.print("Enter the gross pay:");
grossPay = getInput();
System.out.print("Enter the savings rate %:");
savingsRate = getInput();
System.out.print("Gross pay:");
IRARate = getInput();

//calling the method
savingsAmount = doCalculation(grossPay, savingsRate);

//calling the method
IRAAmount = doCalculation(grossPay, IRARate);

//calculating the total amount
total = savingsAmount + IRAAmount;

//calling the method
displayOutput(grossPay, savingsRate, IRARate, savingsAmount, IRAAmount, total);


}

//This method will display the output
private static void displayOutput(double grossPay, double savingsRate,
double iRARate, double savingsAmount, double iRAAmount, double total) {

//DecimalFormat class is used to format the output
DecimalFormat df = new DecimalFormat("#.#");
System.out.printf("Gross pay: %.2f ", grossPay);
System.out.println("Savings rate: %" + df.format(savingsRate));
System.out.printf("Savings amount: %.2f ", savingsAmount);
System.out.println("IRA rate:" + df.format(iRARate) + " %");
System.out.printf("IRA amount: %.2f ", iRAAmount);
System.out.printf("Total of amounts: %.2f ", total);

}


private static double doCalculation(double amount, double rate) {

return amount * (rate / 100);
}

//This method will get the user entered valid inputs
private static double getInput() {

double num;
/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);

while (true) {

num = sc.nextDouble();

if (num < 0) {
System.out.print("Please enter a value greater than 0");
continue;
} else
break;
}
return num;
}

private static void programReq() {
System.out.println("This program calculates savings amounts using methods");


}

}

____________________

Output:

This program calculates savings amounts using methods
Enter the gross pay:10000
Enter the savings rate %:10
Gross pay:5
Gross pay: 10000.00
Savings rate: %10
Savings amount: 1000.00
IRA rate:5 %
IRA amount: 500.00
Total of amounts: 1500.00


_____________Could you rate me well.Plz .Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote