5 Replies - 289 Views - Last Post: 31 January 2011 - 12:11 AM Rate Topic: -----

#1 usernametp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 30-January 11

I cant get this work!

Posted 30 January 2011 - 07:27 PM

import java.util.*;
	import java.text.*;
	
	public class Interest 
		
	{
    static Scanner input = new Scanner(System.in).useDelimiter("\r\n");
	static DecimalFormat fmt = new DecimalFormat("0.00");
	
   
    
   
    public static void main(String[] args) throws Exception
    {
    	int choice=0;
    	int i=0;
    	double [] iPrinciple = new double[4];
	    double [] iEarned = new double [4];
	    double [] iRate = new double [4];
	    int [] iDays = new int [4];
    
    	
    	while (choice !='4')
    	{
    		System.out.println("      Interest Calculator     ");
    		System.out.println("================================");
    		System.out.println("1)Calculate the interest payable");
    		System.out.println("2)Calculate the principle required to earn $x of interest");
    		System.out.println("3)Calculate the time required to earn $x of interest");
    		System.out.println("4)Exit the program");
    		System.out.println("");
    		System.out.print("Please select your choice (1-4): ");
    		choice = input.nextInt();
    		switch(choice)		
    	{
    		case 1 : 	for (i=0; i<10; i++)
    				  	{
    				  		System.out.print("Enter principle amount $: ");
    				  		iPrinciple[i] = input.nextDouble();
    				  		System.out.print("Enter interest rate in %: ");
    				  		iRate[i] = input.nextDouble();
    				  		System.out.print("Enter period rate(time) in days: ");
    				  		iDays[i] = input.nextInt();
    				  		iEarned[i] = (iPrinciple[i]*(iRate[i]/100)*(iDays[i]/360));
    				  		System.out.println(" Interest earned for principle of " + iPrinciple[i] + " at interest rate of " + iRate[i] + " is " + fmt.format(iEarned[i]));
							break;
    					}
    					
    		case 2: for (i=0; i<10; i++)
    				  {
    				  	System.out.print("Enter the interest amount to be earned in $ : ");
    				  	iEarned[i] = input.nextDouble();
    				  	System.out.print("Enter the  interest rate in % : ");
    				  	iRate[i] = input.nextDouble();
    				  	System.out.print("Enter the period<time> in days : ");
    				  	iDays[i] = input.nextInt();
    				  	iPrinciple[i] = (iEarned[i]/((iRate[i]/100)*(iDays[i]/360)));
    				  	System.out.println(" To earn an interest of " + iEarned[i] + " over a period of " + iDays[i] + " you need a principle of " + fmt.format(iPrinciple[i]));
    				  }
    				  break;
    	  	case 3: for (i=0; i<10; i++)
    				  {
    				  	System.out.println("Enter the interest amount to be earned in $ : ");
    				  	iEarned[i] = input.nextDouble();
    				  	System.out.println("Enter the interest rate in % : ");
    				  	iRate[i] = input.nextDouble();
    				  	System.out.println("Enter the principle amount in $: ");
    				  	iDays[i] = input.nextInt();
    				  	iPrinciple[i] = iEarned[i]/(iRate[i]*iDays[i]);
    				  	System.out.println(" To earn an interest of " + iEarned[i] + " over a period of " + iDays[i] + " you need a principle of " + fmt.format(iPrinciple[i]));
    			
    				 }
    				 break;
    				 
    		case 4: for (int j=0; j<i ; j++)
    				{
    					System.out.println("Principle        Rate      Days        Interest                  Total");
    					System.out.println("  ($)             (%)                    ($)                     ($)");
    					System.out.println("---------        ----      ----        --------                  -----");
    					System.out.println(iPrinciple[i] +  iRate[i] + iDays[i] +  iEarned[i]  +    (iPrinciple[i] + iEarned[i]));
    		
    				}
    				break;
    		default: System.out.println("This is an invalid choice, please select 1-4 only ");
    	}
    	
    	System.out.println("");	
    		
}    
}
}//end




Guys! i cant get this working, can someone help??? Please, your help wil be greatly appreciated.

Edited by Dogstopper: :code:

Is This A Good Question/Topic? 0
  • +

Replies To: I cant get this work!

#2 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2858
  • View blog
  • Posts: 10,963
  • Joined: 15-July 08

Re: I cant get this work!

Posted 30 January 2011 - 07:32 PM

You have GOT to be more specific. What about it isn't working? Is it giving you errors? Is the behavior different than you expected?
Was This Post Helpful? 0
  • +
  • -

#3 usernametp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 30-January 11

Re: I cant get this work!

Posted 30 January 2011 - 07:38 PM

Possible lost of precision.
Was This Post Helpful? 0
  • +
  • -

#4 bcranger  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,199
  • Joined: 01-February 10

Re: I cant get this work!

Posted 30 January 2011 - 07:43 PM

The program may be running fine for you, but when I run it, I get an infinite number of prompts due to you setting a delimiter on your scanner:
useDelimiter("\r\n"); 


No reason to use a delimiter in your program.
Was This Post Helpful? 0
  • +
  • -

#5 usernametp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 30-January 11

Re: I cant get this work!

Posted 30 January 2011 - 07:50 PM

I'm sorry, but it doesnt run that well for me, it doesnt calculate :( & we need to use useDelimiter, its part of the programming required.
Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10186
  • View blog
  • Posts: 37,613
  • Joined: 27-December 08

Re: I cant get this work!

Posted 31 January 2011 - 12:11 AM

It would be helpful if you told us at what line the error occurred. Also, don't use parallel arrays.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1