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();
interest[i] = principle[i] * ((rate[i]/100)*(days[i]/365));
System.out.println("Interest earned for principle of $" + principle[i]+" at interest rate of " +rate[i]+ "% is $" + interest[i]);
System.out.println(" ");
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 use arrays to display what the user has entered when they select choice 4. I'm also pulling my hair out figuring how to use method call in my code. Any help would be greatly appreciated.
EDIT: the current code is working, just don't know how to use array. Also, im using jcreator