申し訳ありません。私は現金レジスターファイルにレジスターJavaファイルとretailItemファイルを作成しました。java:29:エラー:RetailItemにプライベートアクセスがあります。
:私は現金レジスタファイルに私のretailItemクラスで書いたプライベート変数は、だからここはここretailItem
import java.text.DecimalFormat;
public class RetailItem
{
private String description;
private double price;
private double unitsOnHand;
private CostData cost;
public void setDescription(String userDescription)
{
description = userDescription;
}
public void setPrice(double p)
{
price = p;
}
public void setUnitsOnHand(double userUnitsOnHand)
{
unitsOnHand = userUnitsOnHand;
}
public String getDescription()
{
return description;
}
public double getPrice()
{
return price;
}
public double getUnitsOnHand()
{
return unitsOnHand;
}
public RetailItem(RetailItem object2)
{
description = object2.description;
price = object2.price;
unitsOnHand = object2.unitsOnHand;
cost = new CostData(object2.cost.wholeSale,object2.cost.Retail);
}
public RetailItem(String descriptionGet,double pri, double
unitsOnHandGet,double wholeSale,double retail)
{
description = descriptionGet;
price = pri;
unitsOnHand = unitsOnHandGet;
cost = new CostData(wholeSale,retail);
}
public String toString()
{
String str;
DecimalFormat dollar = new DecimalFormat("#,##0.00");
str = "Description: " + description +
"Item Price: " + price +
"\nItem Number: " + unitsOnHand +
"\nWhole Cost: $" + dollar.format(cost.wholeSale) +
"\nRetail Price: $" + dollar.format(cost.Retail);
return str;
}
public class CostData
{
public double wholeSale;
public double Retail;
public CostData(double whole,double re)
{
wholeSale = whole;
Retail = re;
}
public void setRetail(double re)
{
Retail = re;
}
public void setWholeSale(double whole)
{
wholeSale = whole;
}
public double getRetail()
{
return Retail;
}
public double getWholeSale()
{
return wholeSale;
}
}
}
のための私のコードだとアクセスできますどのように私の質問は、キャッシュレジスタークラスです
public class CashRegister
{
private RetailItem retail;
private int quantityItem;
private final double SALES_TAX = 0.06;
private int subTotal;
public CashRegister()
{
quantityItem = 0;
subTotal = 0;
}
public CashRegister(RetailItem retailObject,int quantity)
{
retail = new RetailItem(retailObject);
quantityItem = quantity;
}
public RetailItem getRetailItem()
{
return new RetailItem(retail);
}
public double getSubTotal()
{
return quantityItem * retail.cost.getRetail();//Here is where the problem is
}
public double getTax()
{
return SALES_TAX;
}
public double getTotal()
{
return subTotal + SALES_TAX;
}
}
価格と説明がすでにあるように、ゲッターを作成してください。 – azurefrog