該計劃的目的是印刷迎接客戶,然後向他們提供有關銷售價格和價格的信息,然後詢問客戶需要的每件商品的數量。銷售收據的Java程序
該程序應該能夠顯示總數並詢問客戶付多少錢,並最終顯示包含物品,物品價格,數量,產品成本,小計,折扣,稅收,總計的收據,付款和客戶的變化。
商店的物品價格爲:T恤18.95美元,一包薯片1.79美元,12包可樂(2.20美元),2.99美元。
除可口可樂之外的所有商品都以低於標價的15%的價格出售。 T恤也收取6%的密歇根州銷售稅。
我在寫程序和使用java相當新,所以所有的幫助將不勝感激。以下是我迄今爲止編寫的代碼:
import java.util.Scanner;
//The purpose of this program is to simulate the shopping process by calculating the costs of the items
//and producing a receipt for the shopping trip.
//CPS 180
//Joseph Eastman
//September 24, 2014
public class StoreReceipt {
static final double TSHIRT_PRICE = 16.1075;
static final double CHIPS_PRICE = 1.5215;
static final double COKE_PRICE = 2.99;
String a;
static int numberShirts;
static int numberChips;
static int numberCoke;
static double tshirtTotal = TSHIRT_PRICE * numberShirts;
static double chipsTotal = CHIPS_PRICE * numberChips;
static double cokeTotal = (COKE_PRICE + 1.20) * numberCoke;
static double finalTotal = tshirtTotal + chipsTotal + cokeTotal;
{
}
private static Scanner input;
public static void main(String[] args) {
input = new Scanner(System.in);
System.out.println("What's your name?");
String a = input.nextLine();
System.out.println("Welcome to Denny's Market, " + a + "! We have the following items for sale:");
System.out.println("T-shirt $18.95 15% off");
System.out.println("Chips $1.79 15% off");
System.out.println("Coke $2.99");
System.out.println("How many T-shirts do you want?");
String numberShirts = input.nextLine();
System.out.println("How many bags of potato chips?");
String numberChips = input.nextLine();
System.out.println("What about 12-pack coke?");
String numberCoke = input.nextLine();
tshirtTotal = tshirtTotal * .85;
chipsTotal = chipsTotal * .85;
tshirtTotal = tshirtTotal * 1.06;
System.out.println("Your total is: " + finalTotal);
}
}
現在當我輸入的輸入中我得到0的總我和它說我沒有使用任何我的變量。產品數量的輸入可以是任何東西,只需要正確計算總數並改變客戶應該收到的數量。
這裏的輸出應該是什麼時候計劃完成,跑起來像一個例子:
What’s your name? John
Welcome to Denny’s Market, John! We have the following items for sale:
T-shirt $18.95 15% off
Chips $ 1.79 15% off
Coke $ 2.99
How many T-shirts do you want? 3
How many bags of potato chips? 4
What about 12-pack Coke? 2
Your total is $65.69.
Please enter your payment: 70
John, here is your receipt:
item unit price how many cost
--------------------------------------------------------
T-shirt 18.95 3 56.85
Chips 1.79 4 7.16
Coke 2.99 2 5.98
Deposit 2.40
Subtotal 72.39
Discount -9.60
Tax 2.90
----------
Total 65.69
Payment 70.00
Your Change 4.31
Thank you. Come Again!
你能給我們提供樣品輸入,預期產量和實際產量嗎?你的問題有點過於寬泛,似乎你已經打印出總數。 – 2014-09-24 18:01:48
我編輯了這篇文章,並添加了程序運行後的輸出結果。 – 2014-09-24 18:50:07
您當前的輸出是什麼?你得到什麼錯誤? – APerson 2014-09-24 19:24:43