我正在尝试制作一个程序,跟踪热狗站和他们销售的热狗数量,同时制作它我有两个文件,这是第一个,它指向括号,我不确定是什么它意味着需要一个标识符。这是代码
public class HotDogStand
{
private String nameHotDogStand;
private String IDnumber;
private int hotDogsSold;
public HotDogStand(String nameHotDogStand, String IDnumber, int hotDogsSold)
{
this.nameHotDogStand = nameHotDogStand;
this.IDnumber = IDnumber;
this.hotDogsSold = hotDogsSold;
}
public String getNameHotDogStand()
{
return nameHotDogStand;
}
public void setNameHotDogStand(String nameHotDogStand)
{
this.nameHotDogStand = nameHotDogStand;
}
public String getIDnumber()
{
return IDnumber;
}
public void setIDnumber(String IDnumber)
{
this.IDnumber = IDnumber;
}
public int getHotDogsSold()
{
return hotDogsSold;
}
public void setHotDogsSold(int HotDogsSold)
{
this.hotDogsSold = hotDogsSold;
}
public void SetJustSold(int hotDogsSold)
{
hotDogsSold++;
totalHotDogsSold++;
}
public void showHotDogsSold(int hotDogsSold)
{
System.out.print("The number of hot dogs sold is: " + hotDogsSold);
}
private static int totalHotDogsSold;
public String showTotalHotDogsSold()
{
return ("The total number of hot dogs sold is: " + totalHotDogsSold);
}
public String toString()
{
return "The total number of hot dogs sold is: " + totalHotDogsSold;
}
public HotDogStand(HotDogStand otherHotDogStand)
{
nameHotDogStand = otherHotDogStand.nameHotDogStand;
hotDogsSold = otherHotDogStand.hotDogsSold;
IDnumber = otherHotDogStand.IDnumber;
}
public String toString()
{
return("Total sold =" + (one.getNumSold() + two.getNumSold() +
three.getNumSold()) + "\n");
}
one.SetJustSold();
two.SetJustSold();
three.SetJustSold();
}
和我在第二个文件上不确定的第二个问题。我是否需要将“返回”置于公众之下但位于名称热点之上,还是其他问题?
public class TheHotDogStands
{
public static void main(String[]args)
{
HotDogStand one = new HotDogStand ("Bob's hotdog stand" , "0081" , "5");
HotDogStand two = new HotDogStand ("Chris's hotdog stand" , "4591" , "3");
HotDogStand three = new HotDogStand ("Matt's hotdog stand" , "1171" , "10");
System.out.println(one.getName + one.getID + one.getNumSold);
System.out.println(two.getName + two.getID + two.getNumSold);
System.out.println(three.getName + three.getID + three.getNumSold);
System.out.println("Total sold for all stands = " + (one.getNumSold() +
two.getNumSold() + three.getNumSold()));
}
public one(one aOne)
{
nameHotDogStand = aNameHotDogStand;
IDnumber = aIDnumber;
hotDogsSold = aHotDogsSold;
}
}
我还是编程的新手,遗憾的是我的书并不是很擅长解释事情,我的导师说这本书之所以被选中,是因为它适用于他们教授的两个课程,所以有没有哪个好的网站都有可能有一些指南很好的例子?我有时会发现一些,但它们似乎分散在不同的来源和网站上。
感谢您的任何信息。
答案 0 :(得分:1)
在第一个中,你有任何方法之外的这些行:
one.SetJustSold();
two.SetJustSold();
three.SetJustSold();
它们需要位于方法或静态初始化程序块中。
在第二个中,您从未声明one()
的返回类型。