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

    Default Enter number of rooms then call readRoom() method

    I need a bit of help, i want to be able to enter the number of rooms of a house using the keyboard, then whatever number i entered I want to call the readRoom() method which contains information on a room and will add a room to an arraylist. Any help would be great thanks.

    import java.util.Scanner;
    import java.util.ArrayList;
    import java.util.*;

    public class House {

    private int idNum;
    private static int internalCount = 0;
    private String address;
    private int numRooms;

    private String houseType;
    private String roomInfo;

    ArrayList <Room> roomlist=new ArrayList<Room> ();
    Room r=null;

    public House (String address, int numRooms, String houseType, String roomInfo) {
    idNum = internalCount++;

    this.address = address;
    this.numRooms = numRooms;
    this.houseType = houseType;
    this.roomInfo = roomInfo;

    //added this for convenience - could also have this code in PropertyMenu and call 3-arg cons
    public House () {
    idNum = ++internalCount;

    Scanner scan = new Scanner(;

    System.out.println("Enter address of house:");
    address =;

    System.out.println("Enter type of house:");
    houseType =;

    Scanner scan2 = new Scanner(;

    System.out.println("Enter number of rooms:");
    numRooms = scan2.nextInt();

    while (numRooms>0)


    int getIdNum() {
    return idNum;

    public void readRoom () {
    Room r= new Room ();

    public double getHouseArea()
    return r.getArea();

    public String toString() {
    String result;

    result = "ID number:\n" + idNum + "\n";
    result += "Address:\n" + address + "\n";
    result += "Type of House:\n" + houseType+ "\n";
    result += "Number of Rooms:\n" + numRooms + "\n";
    result += "Room Info:\n" + r + "\n";
    result += "House Area:\n" + getHouseArea() + "\n";

    return result;


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

    Default Re: Enter number of rooms then call readRoom() method

    Locking this one as the other one has code tags (and a reply).
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 3
    Last Post: 03-11-2013, 03:03 PM
  2. how to enter input method name for getMethod(------)
    By Dayanand in forum New To Java
    Replies: 3
    Last Post: 02-23-2011, 07:07 PM
  3. Replies: 3
    Last Post: 01-01-2011, 03:36 AM
  4. chat rooms
    By krati in forum Networking
    Replies: 0
    Last Post: 01-28-2010, 06:05 PM
  5. cannot call private method from static method
    By jon80 in forum New To Java
    Replies: 3
    Last Post: 05-07-2008, 08:37 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