Results 1 to 3 of 3
  1. #1
    dangerzone9k is offline Member
    Join Date
    Apr 2009
    Rep Power

    Default Need help with program: arrays

    Hello, this is a program given to me and I need some help writing the code for it.

    You are to create a well‐documented, well‐designed Java application that displays information for of a House and its rooms. The user/House owner would like to enter the names of the rooms in the house at the beginning of the execution of the application. Once the names are entered, the application should continue to ask the user to enter the dimensions of the room i.e. Length and width.
    At the conclusion of the execution, a summary should be provided. The summary should include: The names of all the rooms; the dimensions of the rooms entered. Additionally, the user should be display the Total Size, Average Room Size and the Biggest Room.

    For this program I need to use arrays. How many arrays should I create...4?

    Also, should I create the arrays in the main method?

    import javax.swing.JOptionPane;
    public class House {

    * @param args
    public static void main(String[] args) {
    // TODO Auto-generated method stub

    String[] ownerName = new String;

    int numofRooms;
    int roomLength;
    int roomWidth;
    String roomName;

    numofRooms= integer.parseInt(JOptionPane.showInputDialog("How many rooms in this house?"));

    string[] rooms =new string[numofRooms];

    roomName= JOptionPane.showInputDialog("Enter a name for room#1?");

    roomLength= integer.parseInt(JOptionPane.showInputDialog("What is the lenght of the" + roomName);

    roomWidth= integer.parseInt(JOptionPane.showInputDialog("What is the width of the" + roomName);



  2. #2
    k4ff1n34dd1c7 is offline Member
    Join Date
    Sep 2008
    Rep Power


    First off I was taught in all my programming classes to only use class and method calls in your main();

    I would create an array for the room names
    String[] roomName = new String[the num of rooms]

    Since you only need to know the total size, biggest room and avg room size.

    Create a second array of the area of the room sizes.
    int[] sizes = new int[same size as room name];

    Then right after the user inputs the length and width multiply them and store them in the array.

    What you doing is creating parallel arrays. so index 0 of roomName and sizes refer to the same room.

    So first ask the number of rooms.
    Then get the room names and length and width.
    Java Code:
    for(int i = 0; i < numberOfRooms; i++){
             int length;
             int width;
             ask the room name and store in roomName[i]
             ask the length and width and store in length and width
             sizes = (length * width)
    that get all your data in. then just use three more for loops one to find the biggest another to sum all the areas up, and a third to average them.

  3. #3
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Hong Kong
    Rep Power


    why dont use int ttlSize = 0,
    and increment ttlSize by sizes in each looping

    and add two more variables biggestRoom, biggestRoomSize to store the Name of room, compare and update them in each looping?

Similar Threads

  1. Replies: 2
    Last Post: 11-18-2008, 10:44 PM
  2. Need help with Arrays
    By dietgal in forum New To Java
    Replies: 21
    Last Post: 10-08-2008, 01:59 PM
  3. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  4. Replies: 2
    Last Post: 01-07-2008, 07:45 PM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 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