judith schrieb:
> dear someone who can help
> The first attachment is the program i wrote the second attachment is
[quoted text clipped - 4 lines]
> unexpected type required variable s1.getTotalSold() = s1.getNumSold +
> s2.getNumSold + s3.getNumSold;
You can't assign a value to the return value of a method.
> also i don't know what code to put in the public void justSold() and i
> don't know how to add justSold each time something is sold to the
> getNumSold and i don't know what to program in the public void
> justSold() any suggestions or help please judith the program is below
You don't have any idea of Java, right?
Your code has a few errors:
// we want to increase both, the numSold and the totalSold values
public void justSold() {
numSold++;
totalSold++;
}
// nothing to increase here
public int getNumSold() {
return numSold;
}
// should be a static method since it accesses a static variable
public static int getTotalSold()
In the main method:
- remove anything between the last HotDogStand declaration (s3) and "int i"
- keep the following three for loops (those who call justSold) but
ensure that they count up to different maximum values (not always 5)
- remove the following three for loops (those who call getNumSold)
because they're useless
- remove the s1.getTotalSold() = ... line
- replace the last System.out.println line by
System.out.println("Total sold = " +
HotDogStand.getTotalSold() + "\n");
Bye
Michael