我想製作一個程序,記錄熱狗攤位以及它們銷售多少熱狗,同時使它有兩個文件,這是第一個,它指向括號,我不確定它是什麼意味着需要一個標識符。下面是我不知道關於第二個文件中的代碼需要標識符是什麼意思?
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();
}
和第二個問題。我需要把「回報」的市民,但nameHotDogStand以上,或者是一些其他的問題嗎?
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;
}
}
我還是新的編程和可悲的是我們的書是沒有解釋的事情非常好,我的老師說,之所以選擇這本書,因爲它爲他們傳授所以有什麼好的網站有導引兩班這可能有一些很好的例子嗎?我有時候會發現一些,但他們似乎是從不同的渠道和網站分發出去的。
感謝您的任何信息。
看着這段代碼,我不認爲你真的明白髮生了什麼。你可能想退後一步,從「你好世界」開始,然後從那裏開始。一本優秀的書將是O'Reily&Associates的「學習Java」或Oracle自己的在線系列文章:http://download.oracle.com/javase/tutorial/java/index.html – 2011-03-25 01:50:26