我做了一个应用程序,我计算珠宝店的成本并使用主要方法中的方法。
此方法必须使用 3 次,仅更改一个参数。我还不断收到来自 Java 的错误,说方法和变量已经定义,
这是我的代码:
import java.text.DecimalFormat;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class JewelleryStore
{
public static void main(String[] args)
{
double stateRate = 0.1;
double luxuryRate = 0.2;
double laborRate = 0.05;
double extraCharge;
int numOrdered;
double diamondCost;
double settingCost;
double baseCost;
double totalCost;
double laborCost;
double stateTax;
double luxuryTax;
double finalAmountDue;
Scanner keyInput = new Scanner(System.in);
System.out.println("What is the cost of the diamond?");
diamondCost = keyInput.nextDouble();
System.out.println("What is the cost of the setting?");
settingCost = keyInput.nextDouble();
System.out.println("How many rings are you ordering?");
numOrdered = keyInput.nextInt();
baseCost = diamondCost + settingCost;
calcExtraCost(baseCost, laborRate);
laborCost = extraCharge;
calcExtraCost(baseCost, stateRate);
stateTax = extraCharge;
calcExtraCost(baseCost, luxuryRate);
luxuryTax = extraCharge;
totalCost = baseCost + laborCost + stateTax + luxuryTax;
finalAmountDue = numOrdered*totalCost;
DecimalFormat dollar = new DecimalFormat("0.00");
JOptionPane.showMessageDialog(null, "Jasmine Jewelry INC: TOTAL COST BREAKDOWN" + "\nDiamond Cost: $" +dollar.format(diamondCost) + "\nSetting Cost: $" + dollar.format(settingCost) + "\nState Tax @ 10%: $" + dollar.format(stateTax) + "\nLuxury Tax @ 20%: $" + dollar.format(luxuryTax)+"\nLabor Charge @ 5%: $"+dollar.format(laborCost)+"\nTotal Price: $" + dollar.format(diamondCost+settingCost+stateTax+luxuryTax+laborCost) +"\n\nNumberOrdered: " + numOrdered + "\n\nAmount Due $" + dollar.format(finalAmountDue));
}
public static double calcExtraCost(double diamond, double rate)
{
double extraCharge = diamond*rate;
double diamond = baseCost;
double rate = laborCost;
}
public static double calcExtraCost(double diamond2, double rate2)
{
double extracharge = diamond2*rate2;
double diamond = baseCost;
double rate2 = stateTax;
}
public static double calcExtraCost(double diamond2, double rate3)
{
double extracharge = diamond1*rate3;
double diamond2 = baseCost;
double rate3 = luxuryTax;
}
}