Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: How can you get the compiler to run more than one public class?

  1. #1
    Member
    Join Date
    Feb 2012
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default 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.


    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?


  2. #2
    Forum VIP
    Join Date
    Oct 2010
    Posts
    275
    My Mood
    Cool
    Thanks
    32
    Thanked 54 Times in 47 Posts
    Blog Entries
    2

    Default Re: How can you get the compiler to run more than one public class?

    Rename the file, because

    Quote Originally Posted by tai8 View Post
    class HotDogStand is public, must be declared in a file named HotDogStand.java.

Similar Threads

  1. What's difference between public class and abstract class?
    By Java95 in forum Java Theory & Questions
    Replies: 7
    Last Post: January 24th, 2012, 07:37 AM
  2. Map compiler error
    By kc120us in forum Collections and Generics
    Replies: 4
    Last Post: September 21st, 2011, 10:53 PM
  3. Public class help/error
    By Plural in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 11th, 2010, 05:22 PM
  4. sql compiler
    By tsuki in forum JDBC & Databases
    Replies: 6
    Last Post: October 16th, 2009, 10:35 PM
  5. Private or public variables??
    By igniteflow in forum Java Theory & Questions
    Replies: 2
    Last Post: September 17th, 2009, 08:07 AM