エラー:未解決のコンパイルの問題:RetailItemは変数に解決することはできません

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

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=19313&siteId=1