我需要帮助的是这个,我通过创建下面的简单销售计算器来学习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