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

Edited 5 Years Ago by hoven: n/a

"The question is required to use arrays to display what the user has entered when they select choice 4 "
@above
Do you want to display all the previously entered choices by a user when he finally presses 4.?

sorry for the late reply, my computer went bust few days ago.
@adarshcu, yes, it is required to displayed what the user has previously entered (principle, days, rate, interest and total), after the user choose option 4 before exiting the program

Edited 5 Years Ago by hoven: n/a

I don't think it'l be wise to display all the previously selected values. What can be done is to display the last chosen option and the values. Since you are implementing a do-while loop, the number of times the loop is run is left to the user , he may run the loop ten times or twenty times, which is known only at runtime. One way to do this is to encapsulate all the values into an object and create an array of objects . My real point is why would you want to display all the values that the user has entered till now .? Is it really required ?

Edited 5 Years Ago by adarshcu: n/a

right, i just asked my teacher about this and he says at least 10 of the previous entries must be shown..

This article has been dead for over six months. Start a new discussion instead.