Results 1 to 6 of 6
  1. #1
    Jill is offline Member
    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0

    Default Error: '.class' expected

    Hi, i've searched for this but can't find anythign that ca help me. I'm new to Java and I cannot fix this problem.

    I have created a class (FoodMenuItem) and have created and array of instances of this object (menuItem). So now when i want to display the array i get this error message. It seems like it's probably a simple mistake somewhere but i'm useless and need help desperately.

    public class Menu
    {
    //Declarations
    FoodMenuItem[] menuItems = new FoodMenuItem[10];
    Sale[] sales = new Sale[10];

    public Menu()
    {
    LoadDefaultItems();
    DisplayList();
    }

    protected void LoadDefaultItems()
    {
    menuItems[0] = new FoodMenuItem("Cheese burger", "Main meal", 11.5);
    menuItems[1] = new FoodMenuItem("Gatsby", "Main meal", 8.5);
    menuItems[2] = new FoodMenuItem("Cappuccino", "Drink", 10.25);
    menuItems[3] = new FoodMenuItem("Hot wings", "Starter", 6);
    menuItems[4] = new FoodMenuItem("Fish and chips", "Main meal", 9.5);
    menuItems[5] = new FoodMenuItem("Coffee", "Drink", 5);
    menuItems[6] = new FoodMenuItem("zzzz", "zzz", 0.0);
    menuItems[7] = new FoodMenuItem("zzzz", "zzz", 0.0);
    menuItems[8] = new FoodMenuItem("zzzz", "zzz", 0.0);
    menuItems[9] = new FoodMenuItem("zzzz", "zzz", 0.0);

    sales[0] = new Sale();
    sales[1] = new Sale();
    sales[2] = new Sale();
    sales[3] = new Sale();
    sales[4] = new Sale();
    sales[5] = new Sale();
    sales[6] = new Sale();
    sales[7] = new Sale();
    sales[8] = new Sale();
    sales[9] = new Sale();
    }

    public void DisplayList()
    {
    for(int i = 0; int < 10; i++)
    System.out.println(menuItems[i]);
    }


    }

    Please assist, what am I missing?

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    786
    Rep Power
    5

    Default

    for(int i = 0; int < 10; i++)

    -->

    for(int i = 0; i < 10; i++)

  3. #3
    Jill is offline Member
    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0

    Default

    O MY WORD!!!!!!!!!!!

    Shoot me now!

    Thank you for pointing out the obvious!!!

    Please delete this thread and save me from the embarrassment.....

  4. #4
    Join Date
    Jul 2011
    Posts
    11
    Rep Power
    0

    Default

    for-loop of DisplayList method is the issue......

    here is the code

    public void DisplayList()
    {
    for(int i = 0; i < 10; i++)
    System.out.println(menuItems[i]);
    }

    but it will print all the object's .

    if u have getters, u can retain all the individual members of that object

  5. #5
    Jill is offline Member
    Join Date
    Jul 2011
    Posts
    3
    Rep Power
    0

    Default

    Thank you. I want it display everything, that's just for now.

  6. #6
    Join Date
    Jul 2011
    Posts
    11
    Rep Power
    0

    Default

    k cool , hope u find what u went wrong?

    That's part of learning

Similar Threads

  1. ';' expected error
    By collwill in forum New To Java
    Replies: 3
    Last Post: 05-03-2011, 07:51 AM
  2. Replies: 2
    Last Post: 10-02-2010, 02:13 AM
  3. Class Expected error
    By Radman23 in forum New To Java
    Replies: 11
    Last Post: 01-14-2009, 04:12 AM
  4. MSG ERROR: : expected
    By Marty in forum New To Java
    Replies: 1
    Last Post: 05-31-2007, 02:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •