【发布时间】:2015-09-08 07:19:01
【问题描述】:
我一直在开发一个找零计算器,它将输入 1) 客户姓名、2) 商品描述、3) 商品的购买价格和 4) 客户投标的金额。输出客户名称、描述、成本(带小数点)、投标金额(带小数点)和一美元钞票、25美分硬币、5美分硬币和便士的变化。
这是我目前所拥有的,当我编译和运行它时,当它得到一角硬币和便士时,它给了我错误的变化量。
/* CCTPG22 : Assignment02_ Changer
* @author Kevin Trujillo
* @version 8/30/2014
* Purpose: Your program will take input for the customer name,
the item description, purchase price of an item and
the amount tendered by the customer. Output the customer
ame, description, cost (with decimal point), amount tendered
(with decimal point) and change in one dollar bills, quarters,
ickels, dimes and pennies.
* Status: In Progress
*/
import java.util.*;
public class Assignment02_Changer
{
public static void main(String[] args)
{
String costumer_Name ; // Variables Declared
String item_Bought ;
int amt_DUE ;
int amt_PAID ;
final int pennies_per_dollar = 100 ;
final int nickles_per_dollar = 20 ;
final int dimes_per_dollar = 10 ;
final int quarters_per_dollar = 4 ;
final int pennies_value = 1 ;
int change_due ;
int change_left ;
int dollars_returned ; // Amt of dollars returned
int quarters_returned ; // Amt of Quarters returned
int dimes_returned ; // Amt of dimes returned
int nickles_returned ; // Amt of nickles returned
int pennies_returned ; // Amt of pennies returned
Scanner in = new Scanner(System.in); // Intoduces Input Operator
System.out.print("Change making program by Kevin Trujillo. \n") ; // First Series of Outputs and Inputs (self-explanatory)
System.out.print("What is the customer's name? ") ;
costumer_Name = in.nextLine() ;
System.out.print("Provide one line to describe the item: ") ;
item_Bought = in.nextLine() ;
System.out.print("Please enter the item price in pennies: ") ;
amt_DUE = in.nextInt() ;
System.out.print("Please enter the amount tendered in cents ") ;
amt_PAID = in.nextInt() ;
System.out.print(costumer_Name + " bought a " + item_Bought + " for " + amt_DUE ) ;
System.out.print(" and tendered " + amt_PAID + " in cents. \n") ;
change_due = amt_DUE - amt_PAID ; // caluc. total AMT of change returned
dollars_returned = change_due / pennies_per_dollar ; // calcu. AMT of dollars returned
change_left = change_due % pennies_per_dollar ; // finds remainder due
change_due = change_left ;
quarters_returned = change_due / quarters_per_dollar ; // calcu. AMT of quarters returned
change_left = change_due % quarters_per_dollar ; // finds remainder due
change_due = change_left ;
dimes_returned = change_due / dimes_per_dollar ; // finds remainder due
change_left = change_due % dimes_per_dollar ; // calcu. AMT of dimes returned
change_due = change_left ;
nickles_returned = change_due / nickles_per_dollar ; // finds remainder due
change_left = change_due % nickles_per_dollar ; // calcu. AMT of nickles returned
change_due = change_left ;
dimes_returned = change_due / dimes_per_dollar ; // finds remainder due
change_left = change_due % dimes_per_dollar ; // caluc. AMT of dimes returned
change_due = change_left ;
pennies_returned = change_due / pennies_per_dollar ; // finds remainder due
System.out.print(costumer_Name + "'s change is: \n" );
System.out.printf(" " + dollars_returned + " one-dollar bill (s)\n") ;
System.out.printf(" " + quarters_returned + " quarter (s)\n" ) ;
System.out.printf(" " + dimes_returned + " dime (s)\n") ;
System.out.printf(" " + nickles_returned + " nickle (s)\n") ;
System.out.printf(" " + pennies_returned + " penny (ies)\n") ;
System.out.print("Thank you for your business. Come back soon " + costumer_Name + "!\n" ) ;
} // braces for the main class
} // braces for the program
所以我的问题是我的代码中是否出现算术错误,或者您是否能看到我看不到的东西。
This is an example of what the program should look like.
Change making program by Don Smith
What is the customer's first name? Bob
Provide one line to describe the item: Chem Book
Please enter the item price in cents: 3458
Please enter the amount tendered in cents: 4000
Bob bought a Chem Book for 34.58 and tendered 40.00
Bob's change is:
5 one-dollar bill(s)
1 quarter(s)
1 dime(s)
1 nickel(s)
2 penny(ies)
Thanks for your business. Come back soon.
【问题讨论】:
-
以您的真实姓名在这里发布您的作业可能不是最好的主意。
标签: java math calculator