Results 1 to 3 of 3
  1. #1
    Ronan23 is offline Member
    Join Date
    Mar 2013
    Rep Power

    Default House/Room Classes

    Im currently doing as assignment where I have two classes Room and House, the house class stores rooms in an arraylist. Im a bit confused over this one part of the assignment. Any help would be greatly appreciated.

    *Implement a method to read in room information in the House class from the keyboard — this should call the Room constructor as required. Create a zero-argument House constructor to call this new method.

    Java Code:
    import java.util.Scanner;
    import java.util.ArrayList;
    public class House {
      private int idNum;
      private static int internalCount = 0;
      private String address;
      private int numRooms;
      private String houseType;
      public House (String address, int numRooms, String houseType) {
        ArrayList<Room> rooms = new ArrayList<Room>();
        idNum = internalCount++;
        this.address = address;
        this.numRooms = numRooms;
        this.houseType = houseType;  
      public House () {
        idNum = ++internalCount;
        Scanner scan = new Scanner(;
        System.out.println("Enter address of house:");
        address =;
        System.out.println("Enter number of rooms:");
        numRooms = scan.nextInt();
        System.out.println("Enter type of house:");
        houseType =;
      int getIdNum() {
        return idNum;
       public String toString() {
         return address + "- Num rooms: " + numRooms + ' ' + houseType + '\n';
    import java.util.Scanner;
    public class Room {
      private String description;
      private double length;
      private double width;
      public Room (String description, double length, double width) {
        this.description = description;
        this.length = length;
        this.width = width;     
      public Room () {
        Scanner scan = new Scanner(;
        System.out.println("Enter description of room:");
        description =;
        System.out.println("Enter length of room:");
        length = scan.nextDouble();
        System.out.println("Enter width of room:");
        width = scan.nextDouble();
       public double getArea () {
         return length*width;
       public String toString() {
         return description + "- Length: " + length + "m; Width: " + width + 'm';
    Last edited by Ronan23; 03-11-2013 at 05:06 PM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power

    Default Re: House/Room Classes

    Please wrap your code in
    Java Code:
    so it retains its formatting.

    Your House class doesn't appear to have a 'rooms' attribute.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power

    Default Re: House/Room Classes

    The assignment wants you to implement a readRoom() method in your House class; the method should read the necessary information from the keyboard and construct a Room out of it; it should add the Room to the ArrayList<Room> in the House object.

    kind regards,

    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. Replies: 6
    Last Post: 08-18-2012, 09:54 AM
  2. Chat Room in JSP
    By c.P.u1 in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 07-07-2011, 03:23 PM
  3. Chat Room help
    By Noelf21 in forum New To Java
    Replies: 2
    Last Post: 01-13-2010, 01:28 PM
  4. Hello gurus' in the house
    By javahsm in forum New To Java
    Replies: 0
    Last Post: 11-29-2008, 06:11 PM
  5. building a house
    By dc2acgsr99 in forum Java Applets
    Replies: 4
    Last Post: 03-07-2008, 11:18 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