2 回答
TA贡献1802条经验 获得超4个赞
创建一个自定义对象,可能称为Combo
. 那么该Combo
对象将具有两个属性:
描述
价钱
您可以Combo
通过传入Description
和Price
作为参数来创建对象。然后您将添加一个getDescription()
andgetPrice()
方法,以便您可以访问该类的数据。
这是创建自定义对象的基础知识。
public class Combo
{
private String description;
private double price;
public Combo(String desctiption, double price)
{
this.description = description;
this.price = price;
}
public String getDesctiption()
{
return description;
}
public double getPrice()
...
}
我会让你填空。
TA贡献1812条经验 获得超5个赞
如果您是初学者,那么您可能还没有学习过课程。
另一种方法是使用数组。
String[] orders = new String[4];
orders[0] = "1 Pizza large 14\", 12 chicken wings, and 1 medium fries;24.99";
// TODO: set orders 1..3
然后当你打印收据时,你可以做
for (String o : orders) {
String parts = o.split(";"); // used ; because there are commas within the data
String description = parts[0];
String price = parts[1];
// TODO: print them
}
否则,你会被单个变量困住
String combo1Description;
int combo1Price;
...
哪个不容易循环
添加回答
举报