codewithdanielle:
私は一つだけのエラーを取得していますし、このエラーを修正することができないように、これはあなたが買っているエラーです:ジーンズは、私たちは、在庫12ペアを持っています。ジーンズの価格は以下のとおりです。$ 59.95あなたは?:3を買ってどのくらい
スレッド「メイン」でjava.lang.Errorで******例外:未解決のコンパイルの問題:RetailItemは変数に解決することはできません
public class CashRegisterapp
{
private final double TAX_RATE = 0.06;
private double retail;
private int quantity;
private RetailItem item;
public CashRegisterapp(RetailItem item, int q)
{
RetailItem = item;
quantity = q;
}
public double getSubtotal()
{
return retail * getSubtotal();
}
public double getTax()
{
return getSubtotal() * TAX_RATE;
}
public double getTotal()
{
return getSubtotal() + getTax();
}
}
以下******テストコード******
import java.util.Scanner;
public class HW5
{
public static void main(String[] args)
{
final int unitsOnHand = 12;
final double price = 59.95;
String description = "Jeans";
int quantity;
RetailItem item = new RetailItem(description,unitsOnHand,price);
System.out.print("You are buying: "+ description+ "\nWe have "+ unitsOnHand+ " pair In stock.\nThe price of the jeans are: $"+ price+ "\n");
System.out.print("How much are you buying?: ");
Scanner keyboard = new Scanner(System.in);
quantity = keyboard.nextInt();
CashRegisterapp reg = new CashRegisterapp(item, quantity);
System.out.printf("The subtotal is: $%,.2f\n", reg.getSubtotal());
System.out.printf("The sale tax is: $%,.2f\n", reg.getTax());
System.out.printf("The total is: $%,.2f\n", reg.getTotal());
}
}
ハルク:
あなたはaccidentially書いたRetailItem
代わりのthis.item
のコンストラクタの1行目にCashRegisterapp
。あなたが入力している間ほとんどの編集者は、このような問題を強調すべきです。
public CashRegisterapp(RetailItem item, int q)
{
this.item = item;
this.quantity = q;
}
また、このコードの他の問題があります。
- あなたが
getSubtotal()
自分自身を再帰的に呼び出して、これは、スタックオーバーフローが発生します - あなたは初期化されません。
retail