import java.util.*; import java.text.*; public class Interest { static DecimalFormat fmt=new DecimalFormat("0.00"); //2 decimal place. static Scanner input=new Scanner(System.in).useDelimiter("\r\n"); static double[] principle = new double [10]; static double[] rate = new double [10]; static double[] interest = new double [10]; static double[] days = new double [10]; static int i; static int choice; public Interest() { } public static void main(String[] args) { do { System.out.println(" Interest Calculation "); System.out.println(" ---------------------"); System.out.println("1. Calculate interest payable"); System.out.println("2. Calculate principle required to earn $x of interest"); System.out.println("3. Calculate time required to earn $x of interest"); System.out.println("4. Exit program"); System.out.println(" "); System.out.print("Please select your choice (1-4):"); choice = input.nextInt(); System.out.println("---------------------------------"); switch(choice) { case 1 : //Caluclate interest System.out.print("Enter principle amount in $ :"); principle[i]=input.nextInt(); System.out.print("Enter interest rate in % :"); rate[i]=input.nextDouble(); System.out.print("Enter period(time) in days :"); days[i]=input.nextInt(); System.out.println("Interest earned for principle of $" + principle[i]+" at interest rate of " +rate[i]+ "% is $" + interest[i]); System.out.println(" "); interest[i] = principle[i] * ((rate[i]/100)*(days[i]/365)); break; case 2 : // Calculate principle System.out.print("Enter interest amount to be earned in $ :"); interest[i]=input.nextDouble(); System.out.print("Enter interest rate in % :"); rate[i]=input.nextInt(); System.out.print("Enter period(time) in days :"); days[i]=input.nextInt(); principle[i] = interest[i] / (days[i]/365/rate[i]/100) ; System.out.println("To earn an interest of " +interest[i]+ ", over a period of " +days[i]+ "days, you need a principle of " +principle[i]); System.out.println(" "); break; case 3 : // Calculate days System.out.print("Enter interest amount to be earned in $:"); interest[i]=input.nextDouble(); System.out.print("Enter interest rate in % :"); rate[i]=input.nextDouble(); System.out.print("Enter principle amount in $:"); principle[i]=input.nextInt(); days[i] = interest[i] / ( principle[i] * rate[i]/100 ); System.out.println("To earn an interest of $" +interest[i]+ ", with a principle of $"+principle[i]+ " time required is " +days[i]+ " days"); System.out.println(" "); break; case 4 : //show entries displayed System.out.println("Thank you for using Interest Calculator"); System.out.println(" "); break; default : System.out.println("Please enter 1, 2 or 3"); System.out.println(" "); }//end switch }while (choice!=4); } }
The question is required to display what the user has entered(principle, rate, days,total and interest) when choice 4 is selected. Also, method call is required. The current code is working(loops, choice). Just do not know how to use arrays and method call, any help would be greatly appreciated