I rewrote a project and it compiled sucessfully with no errors. I then went to test the project to make sure it gave me the output I was looking for. It then went matrix. The command prompt was filled with letters jumping on the screen just like in the movie. Can anyone tell me why this is?

Loop not written properly. [Probably an infinite loop]

for (int i=10; i>=0; i++)
{
}


That would be an example.

I did a while loop for a case statement:

while (UnitOfCurrency != 4)

I cannot see why it would be the cause of the problem but I am open to any suggestions at this point.

UnitOfCurrency is never equal to 4. You may be performing some kind of arithmetic that skips four:

you may start out at 3.
Then add two, which is 5. That continues the loop because it's still not four.

Well I choose 4 because I have 3 case statements and 1 default statement. The 4 choice is to exit and to add the total amount converted throughout the entire program.

Do you mind showing me the loop?

Main method:
while (UnitOfCurrency != 4) // set up while statement
{
switch (currency) //use a switch statement to switch currency
{


case 1:
mygifts.USDollarsEntered();
break;


case 2:
mygifts.EurosEntered();
break;


case 3:
mygifts.YenEntered();
break;


default: // total collected
System.out.print ("Exit and add the total collected.");
break;
}


second class method:


public void USDollarsEntered ()
{
System.out.println ("Please enter the number of Dollars.") ;
EnteredDollars = stdin.nextDouble() ; // read in the user input
ConvertedDollars = EnteredDollars * DOLLARS_CONVERSION_RATE ; // Dollar to Dollar conversion
System.out.println ( ) ;
System.out.println (EnteredDollars + " dollars equals " + ConvertedDollars + " dollars.") ;
total += ConvertedDollars;


}


//method to convert Euros to Dollars
public void EurosEntered ()
{
System.out.println ("Please enter the amount of Euros.") ;
EnteredEuros = stdin.nextDouble() ; // read in the user input
ConvertedEuros = EnteredEuros * EURO_CONVERSION_RATE ; // Euro to Dollar conversion
System.out.println ( ) ;
System.out.println (EnteredEuros + " euros equals " + ConvertedEuros + " dollars.") ;
total += ConvertedEuros;


}


//method to convert Yen to Dollars
public void YenEntered ()
{
System.out.println ("Please enter the number of Yen.") ;
EnteredConvertedYen = stdin.nextDouble() ; // read in the user input
ConvertedYen = EnteredConvertedYen * YEN_CONVERSION_RATE ; // Yen to Dollar conversion
System.out.println ( ) ;
System.out.println (EnteredConvertedYen + " yen equals " + ConvertedYen + " dollars.") ;
total += ConvertedYen;


}


//method to calculate Total Savings
public void TotalSavings()
{
TotalSaving = total;
System.out.println ( ) ;
System.out.println ("You have choosen to quit the program.") ;
System.out.println ("Your total amount of savings is " + TotalSaving) ;


}


}

Just as I thought; it's an infinite loop. UnitOfCurrency is never set to four. Now, from what I understand you want to loop until the user enters something other than 1,2,3, correct?

Let me know exactly why you are looping and what you expect it to do so we can fix up something that will work.

Yes, that is correct. I want the user to choose from options 1-4, 1. to convert dollars, 2. to convert euros, 3. to convert yens, or 4. to exit the program (and to do a accumlative total of all money entered by users). The while loop is to move between the different types of currency.

In that case you don't need the while loop.
All you need to do is change the default case statement to exit:

switch (currency) //use a switch statement to switch currency
{

case 1:
mygifts.USDollarsEntered();
break;

case 2:
mygifts.EurosEntered();
break;

case 3:
mygifts.YenEntered();
break;

default: // total collected
System.out.print ("Exit and add the total collected.");
System.exit(0);
break;
}

There's no reason for a while loop. The variable currency is never changed in the while loop, so even if you did create a viable exit condition it would still be an infinite loop. So, just get rid of the loop and everything should work.

Ok. I will try that. Thanks for all your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.