How can you get the compiler to run more than one public class?
I'm having problems with this one question, i have been at it all day now and i still don't get it.
Code :
public class HotDogStand
{
private int id;
private int numSold;
private static int totalSold = 0;
public HotDogStand()
{
id = 0;
numSold = 0;
totalSold = 0;
}
public HotDogStand(int newId, int newNumSold)
{
id = newId;
numSold = newNumSold;
}
public int getId()
{
return id;
}
public void setId(int newId)
{
id = newId;
}
public int getNumSold()
{
numSold ++;
return numSold;
}
public int getTotalSold()
{
return totalSold;
}
public void justSold()
{
totalSold = numSold ++;
}
}
public class program2JS
{
public static void main (String [] args)
{
HotDogStand s1 = new HotDogStand();
HotDogStand s2 = new HotDogStand();
HotDogStand s3 = new HotDogStand();
s1.getId();
s2.getId();
s3.getId();
s1.setId(1);
s2.setId(2);
s3.setId(3);
s1.getNumSold();
s2.getNumSold();
s3.getNumSold();
s1.justSold();
s2.justSold();
s3.justSold();
s1.getTotalSold();
int i;
for(i = 1; i <=5; i++)
s1.justSold();
for(i = 1; i <=5; i++)
s2.justSold();
for(i = 1; i <=5; i++)
s3.justSold();
for(i = 1; i <=5; i++)
s1.getNumSold();
for(i = 1; i <=5; i++)
s2.getNumSold();
for(i = 1; i <=5; i++)
s3.getNumSold();
int TotalSold = s1.getTotalSold() + s2.getTotalSold() + s3.getTotalSold();
//Test our code with three hot dog stands
//sold at stand 1, 2
s1.justSold();
s2.justSold();
s1.justSold();
System.out.println("Stand" + s1.getId() + "Sold" + s1.getNumSold());
System.out.println("Stand" + s2.getId() + "Sold" + s2.getNumSold());
System.out.println("Stand" + s3.getId() + "Sold" + s3.getNumSold());
System.out.println("Total sold = " + s1.getTotalSold() + "\n");
//Sold some more
s3.justSold();
s1.justSold();
System.out.println("Stand" + s1.getId() + "Sold" + s1.getNumSold());
System.out.println("Stand" + s2.getId() + "Sold" + s2.getNumSold());
System.out.println("Stand" + s3.getId() + "Sold" + s3.getNumSold());
System.out.println("Total sold = " + s1.getTotalSold() + "\n");
}
}
I can't get this to run as it keeps saying:
class HotDogStand is public, must be declared in a file named HotDogStand.java. the problem is my file is already called program2JS. Can someone please help me with this?
Re: How can you get the compiler to run more than one public class?
Rename the file, because
Quote:
Originally Posted by
tai8
class HotDogStand is public, must be declared in a file named HotDogStand.java.