Reply
Sat 11 Feb, 2006 05:24 pm
I dont know where to post this message so I post it here.
Im using BlueJ to write a small program, but I cant make it works
Any idea?
Thank you
*****************************
1. Add code to calculate the total cents from the amount of coins. For example, if the coins were 4 pennies, 2 nickels and 1 dime the total cents would be 24.
You do not ask the user for the number of coins. Instead, simply assign a value to the variables you use. For example, nickels = 4;
After you get the calculation working and tested, make these modifications, one at at time:
a. Add if ...else statement(s) to verify that the number of each type of coin is not negative. For example, nickels can't be -4. If any value is negative, don't do the calculation but display an error instead. (Use this command: System.out.println("Error");
b. Count the total number of coins and display it on the screen. (Use System.out.println)
*************************************
Here my code:
public class MoneyToCentsProject
{
/*
* This method converts pennies, nickels, dimes and quarters into cents
*/
public static void ConvertMoney()
{
//Add code below this line
int cents = 0; //do not change this line
int pennies = 1;
int nickles = 2;
int dimes = 3;
int quarters =4;
if (int pennies < 0 || int nickles < 0 || int dime < 0 || int quarters < 0)
{
System.out.prinln("Error")
}
else
{
retrun pennies + nickles * 5 + dimes * 10 + quarters * 25;
}
System.out.println("The answer is: " + cents); //do not change this line
//add code above this line
}
}
}