What does it mean by need identifier?
I am trying to make a program that keeps track of hotdog stands and how much hot dogs they sell and while making it I have two files, this is the first one and it points to the parenthesis and I am not sure by what it means by needed an identifier there. Here is the code
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 IDnu开发者_运维知识库mber;
}
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();
}
and a second problem I am not sure about on the second file. Do I need to put "return" below the public but above the nameHotDogStand, or is it some other problem?
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;
}
}
I am still new to programming and sadly our book isn't very good at explaining things, my instructor said this book was chosen because it works for two classes that they teach so are there any good websites with guides that may have some good examples? I do find a few sometimes but they seem to be spread out from different sources and websites.
Thanks for any info.
In the first one, you've got these lines outside of any method:
one.SetJustSold();
two.SetJustSold();
three.SetJustSold();
They need to be in a method or a static initializer block.
In the second one, you never declared a return type for one()
.
精彩评论