gpt4 book ai didi

java - 需求标识符是什么意思?

转载 作者:行者123 更新时间:2023-12-01 15:54:05 26 4
gpt4 key购买 nike

我正在尝试制作一个程序来跟踪热狗摊位以及他们卖了多少热狗,在制作它时我有两个文件,这是第一个文件,它指向括号,我不确定是什么这意味着那里需要一个标识符。这是代码

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();
}

还有我不确定第二个文件的第二个问题。我是否需要将“return”放在公共(public)下方但名称HotDogStand上方,还是有其他问题?

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;
}
}

我对编程还是个新手,遗憾的是我们的书不太擅长解释事情,我的老师说选择这本书是因为它适用于他们教授的两门类(class),所以有没有任何好的网站提供指南,可能有一些好的例子吗?我有时确实会找到一些,但它们似乎是从不同的来源和网站传播的。

感谢您提供任何信息。

最佳答案

在第一个中,您在任何方法之外都有这些行:

one.SetJustSold();
two.SetJustSold();
three.SetJustSold();

它们需要位于方法或静态初始化 block 中。

在第二个中,您从未声明 one() 的返回类型。

关于java - 需求标识符是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5427617/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com