宝石店のコストを計算し、main メソッド内のメソッドを使用するアプリケーションを作成します。
このメソッドは、1 つのパラメーターのみを変更して 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;
}
}