我需要幫助的是這個,我通過創建下面的簡單銷售計算器來學習Jave。我有這樣的代碼中的部分如下:Java:存儲選定的值供以後使用
System.out.println ("Please make a selection:");
System.out.println ("1. Octopus Tentacles, 2. Rat Droppings");
System.out.println ("3. Sharks teeth, 4. Mountain Oysters");
System.out.println (" ");
// Since we don't have a primary database to pull from we use a dummy DB
while (foodCount <= 1)
{
System.out.print("Enter selection (1 , 2, 3, 4): ");
result = input.nextInt();
if (result == 1)
System.out.println("You selected Octopus tentacles, price $4.99");
else if (result == 2)
System.out.println("You selected Rat droppings, price $3.49");
else if (result == 3)
System.out.println("You selected Sharks teeth, price $6.73");
else if (result == 4)
System.out.println("You selected Mountain Oysters, price $9.95");
break;
}
System.out.println (" ");
它允許選擇向我提出,我想要做的是保存在下面的輸入價格小有一點部分使用該值。有人能幫助我嗎?我是Java的新手,通過自己的閱讀方式學習自己的閱讀書籍,但沒有找到任何能夠幫助我的例子。任何援助與此將不勝感激。
import java.io.*;
import java.text.*;
import java.util.*;
import java.util.Scanner;
import java.math.BigDecimal;
import java.text.NumberFormat;
class priceCalc {
public static void main (String[] args) throws IOException {
BufferedReader in = new BufferedReader (new InputStreamReader (System.in));
Scanner input = new Scanner(System.in);
int Quantity;
int result = 0;
int foodCount = 1;
double Price, Subtotal, SalesTax, TotalSale;
NumberFormat curForm = NumberFormat.getCurrencyInstance();
// Here is a simple display of available products
System.out.println (" ");
System.out.println ("Welcome to the IP2 part 2!");
System.out.println (" ");
System.out.println ("Please make a selection:");
System.out.println ("1. Octopus Tentacles, 2. Rat Droppings");
System.out.println ("3. Sharks teeth, 4. Mountain Oysters");
System.out.println (" ");
// Since we don't have a primary database to pull from we use a dummy DB
while (foodCount <= 1)
{
System.out.print("Enter selection (1 , 2, 3, 4): ");
result = input.nextInt();
if (result == 1)
System.out.println("You selected Octopus tentacles, price $4.99");
else if (result == 2)
System.out.println("You selected Rat droppings, price $3.49");
else if (result == 3)
System.out.println("You selected Sharks teeth, price $6.73");
else if (result == 4)
System.out.println("You selected Mountain Oysters, price $9.95");
break;
}
System.out.println (" ");
// Create Scanner for input
Scanner key = new Scanner(System.in);
//Quantity
System.out.print ("Please enter quantity: ");
Quantity = key.nextInt();
System.out.println (" ");
//Price
System.out.print ("Please input price (price amount w/no $): ");
Price = key.nextDouble();
System.out.println (" ");
//Subtotal
Subtotal = Price * Quantity;
System.out.println ("Your subtotal is: " +curForm.format(Subtotal));
//Sales Tax
SalesTax = Subtotal * .065;
System.out.println ("Your sales tax is: " +curForm.format(SalesTax));
//Total Sale
TotalSale = Subtotal+SalesTax;
System.out.println ("Your total sale price is: " +curForm.format(TotalSale));
System.out.println (" ");
}
}
我仍然沒有得到問題的地方 – 2012-01-14 17:17:52
Theres沒有代碼的問題,它的工作方式,它工作正常。問題是我想要自動化價格,所以當我選擇1,2,3,4以上時,價格將被存儲並在添加數量的數量後被調用爲以下價格的輸入。 – Powercat 2012-01-14 17:21:20