(求助)Java, 拜托各位帮我看一下这个怎样做
我用的是 JCreator, 是我电脑课的作业,后天要交了,拜托大家帮帮忙, 就是要写一个会自动找零钱的程序,5块钱买2.35快糖,剩下的钱要用硬币分类列出来没多少个2快,多少个1快,多少个25分,多少个10分,多少个5分,多少个1分,用的硬币越少越好, 题目是有点长,希望帮帮忙(1) The Change Calculator
You are off to the candy store with a $5 bill to buy some candies. Write a program called
ChangeCalculatorProgram that allows you to enter the total cost of the candies that you are
buying (i.e., use the Scanner class) in cents (i.e., 275 cents is $2.75). The program should
then tell you how many toonies, loonies, quarters, dimes, nickels and pennies that you should
get as your change (assuming that you always pay with a $5 bill).
Your program should return the least amount of coins possible. All your calculations
should be in terms of cents so that you can use just int variables.
Your program should have nice-looking output as follows:
Enter the cost of the candies (in cents): 235
The change from $5.00 for $2.35 of candies is:
1 toonie(s)
0 loonie(s)
2 quarter(s)
1 dime(s)
1 nickel(s)
0 pennie(s)
Notice that amount entered is an integer (i.e., total cents) but the output statement displays the
cost as a float (i.e., dollars). Test your code with the following costs:
0, 25, 100, 101, 107, 150, 235, 400, 498, 499, 500
需要解释的加我qq 452323960, 下面是我写的code, 可以找到要找多少钱,但是我不知道怎样才可以分类列出来
import java.util.Scanner;
class ChangeCalculatorProgram {
public static void main(String args[]) {
int m,c,change;
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter the cost of the candies (in cents):");
m = keyboard.nextInt();
c = keyboard.nextInt();
change = m-c;//compute the change and store it
System.out.println("Given numbers "+m+
"and"+c+
":");
System.out.println("The change from $5.00 for $2.35 of candies is"+change);
System.out.println("The cost is "+c);
}
}
[ 本帖最后由 lyf3368 于 2009-10-6 12:23 编辑 ]