1
   

Java

 
 
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
}
}
}
  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Discussion • Score: 1 • Views: 935 • Replies: 0
No top replies

 
 

Related Topics

Clone of Micosoft Office - Question by Advocate
Do You Turn Off Your Computer at Night? - Discussion by Phoenix32890
The "Death" of the Computer Mouse - Discussion by Phoenix32890
Windows 10... - Discussion by Region Philbis
Surface Pro 3: What do you think? - Question by neologist
Windows 8 tips thread - Discussion by Wilso
GOOGLE CHROME - Question by Setanta
.Net and Firefox... - Discussion by gungasnake
Hacking a computer and remote access - Discussion by trying2learn
 
  1. Forums
  2. » Java
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.03 seconds on 05/03/2024 at 01:32:29