Question: Can someone help me simplify this Java program? I need to simplify it and get the same results. We are in basic Java and my
Can someone help me simplify this Java program? I need to simplify it and get the same results. We are in basic Java and my program is too long. I need to to use if/else and looping.
import java.util.Scanner; public class InterestCalculator { public static void main(String[] args) { int quarters; double startBalance; double intrestRate; double endBalance; double intrestEarned; String ch; Scanner sc=new Scanner(System.in); do { System.out.println("Enter the number of quarters from 1 to 10"); quarters=sc.nextInt(); while(quarters<0 || quarters>10) { System.out.println("The value you entered is not in the range please renter the number of quarters from 1 to 10"); quarters=sc.nextInt();; } System.out.println("Enter beginning principal balance greater than 0"); startBalance=sc.nextDouble(); while(startBalance<0) { System.out.println("The value you entered is not valid please renter beginning principal balance greater than 0"); startBalance=sc.nextDouble(); }
Here is the original question I need to write the program for:
Write a Java program named InterestCalculator.java that calculates the value of a bank account based on starting principle, interest rate and time.
Prompt the user for
Number of quarters to display (int) that is greater than zero and less or equal to 10.
Starting balance (double) that is greater than zero.
Interest rate (double) that is greater than zero and less than or equal to 20%
Display the information the user entered and ask if it is correct. If so continue, if not ask for all the information again (loop and half example in Addition Iteration examples).
Calculate the ending balance for each quarter and display the results in a table similar to below, the formula for quarterly balance is b + (b * IR/100 * .25) where b is starting balance and IR is interest rate :
EX:
Enter number of quarters from 1 to 10
8
Enter beginning principal balance greater than 0
1000
Enter the interest rate percentage without the percent sign
greater than 0% and less than/equal to 20%
5.25
You entered a principal balance of $1000.00 for 8 quarters at 5.25& interest
Is this correct (y/n)
Y
Quarter Beginning Interest Ending
Number Balance Earned Balance
1 $1000.00 $13.13 $1013.13
2 $1013.13 $13.30 $$1026.42
-If the user enters a value outside the boundaries listed above, prompt them with an error message and ask for the value again(Loops).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
