Results 1 to 3 of 3
  1. #1
    Richard2732 is offline Member
    Join Date
    Dec 2009
    Posts
    2
    Rep Power
    0

    Exclamation Convert arrays into lists

    At the moment im trying to create a programme that creates a list of rooms and i need to list the rooms. Also i think i need a static method to list all the rooms i have created outside of the class/constructor.

    Java Code:
    //the constructor sets the Building name and the number of arrays it holds (3 arrays)
    //from its parameter list
    public BuildingV02(String name, int number_of_Lecture_rooms, int number_of_Practical_rooms, int number_of_Tutorial_rooms)
    {
    
    building_name = Console.readString("Enter the building name:");
    
    
    Lecture_count = Console.readInt("Enter the number of Lecture rooms that the building will have:");
    Practical_count = Console.readInt("Enter the number of Practical rooms that the building will have:");
    Tutorial_count = Console.readInt("Enter the number of Tutorial rooms that the building will have:");
    
    System.out.println("The rooms are created in order of type, the Lecture rooms will " +
    "be defined first followed by the Practical rooms and finally the Tutorial rooms");
    
    
    //create the Lecture room objects in an array
    for (int j = 0; j < Lecture_count; j++)
    {
    Lecture_rooms = new Lecture[Lecture_count];
    Lecture_rooms[j] = new Lecture("number not set", 0, false, false, false, false ,false ,false);
    
    }
    
    //create the Practical room objects
    for (int j = 0; j < Practical_count; j++)
    {
    Practical_rooms = new Practical[Practical_count];
    Practical_rooms[j] = new Practical("number not set", 0, false, false, false, false ,false ,false);
    
    }
    
    
    //create the Tutorial room objects
    for (int j = 0; j < Tutorial_count; j++)
    {
    Tutorial_rooms = new Tutorial[Tutorial_count];
    Tutorial_rooms[j] = new Tutorial("number not set", 0, false, false, false, false ,false ,false);
    
    }
    
    }
    I need to find a way either within this constructor or somewhere else to list all three arrays.

    Apologies for any breach of etiquette this is my first post.

    Thanks for any help you can give
    Last edited by Richard2732; 12-28-2009 at 08:49 AM.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,529
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Richard2732 View Post
    public BuildingV02(String name, int number_of_Lecture_rooms, int number_of_Practical_rooms, int number_of_Tutorial_rooms)
    Why are you passing those number_of_XXX_rooms? You don't use them at all in your constructor. Have a look at the Arrays class; it can give you a List view of your arrays.

    kind regards,

    Jos

  3. #3
    Richard2732 is offline Member
    Join Date
    Dec 2009
    Posts
    2
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    Why are you passing those number_of_XXX_rooms? You don't use them at all in your constructor. Have a look at the Arrays class; it can give you a List view of your arrays.

    kind regards,

    Jos
    I think that was left from an older version which was going to use them, i have removed them, thanks :).
    Java Code:
    //the constructor sets the Building name and the number of arrays it holds (3 arrays)
    //from its parameter list
            public BuildingV02(String building_name)
            {
                
                    building_name =  Console.readString("Enter the building name:");
                    
    
                    Lecture_count = Console.readInt("Enter the number of Lecture rooms that the building will have:");
                    Practical_count = Console.readInt("Enter the number of Practical rooms that the building will have:");
                    Tutorial_count = Console.readInt("Enter the number of Tutorial rooms that the building will have:");
    
                    System.out.println("The rooms are created in order of type, the Lecture rooms will " +
                            "be defined first, followed by the Practical rooms, and finally the Tutorial rooms");
    
    
                    //create the Lecture room objects in an array
                   for (int j = 0; j < Lecture_count; j++)
                    {
                        Lecture_rooms = new Lecture[Lecture_count];
                        Lecture_rooms[j] = new Lecture("number not set", 0, false, false, false, false ,false ,false);
    
                    }
    
                    //create the Practical room objects
                   for (int j = 0; j < Practical_count; j++)
                    {
                        Practical_rooms = new Practical[Practical_count];
                        Practical_rooms[j] = new Practical("number not set", 0, false, false, false, false ,false ,false);
    
                    }
    
    
                    //create the Tutorial room objects
                    for (int j = 0; j < Tutorial_count; j++)
                    {
                        Tutorial_rooms = new Tutorial[Tutorial_count];
                        Tutorial_rooms[j] = new Tutorial("number not set", 0, false, false, false, false ,false ,false);
    
                    }
    
            }

Similar Threads

  1. Integers and Lists
    By TGH in forum New To Java
    Replies: 8
    Last Post: 01-27-2010, 09:49 AM
  2. Help with arrays and array lists
    By ambernicole88 in forum New To Java
    Replies: 3
    Last Post: 12-04-2009, 09:47 PM
  3. 2 dimensional Lists
    By gapper in forum New To Java
    Replies: 4
    Last Post: 01-20-2008, 09:01 AM
  4. Tudu Lists 2.1
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 08-10-2007, 04:39 PM
  5. Tudu Lists 2.0
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 07-11-2007, 03:32 PM

Posting Permissions

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