-2

My program should use print and println statements to draw a building on my console window. The building will have a variable number of stories and windows on each story. The windows also will be of varied heights and widths. Everything works fine, but I am having trouble with the width of the windows. I would really appreciate any help!

Is this how to write in pseudo code?

Do how many stories high the building will be? (1-4)
    While stories is less than MINSTORIESHIGH or stories is greater than MAXSTORIESHIGH
Do how many windows on each story? (1-4)
    While windows is less than MINWINDOWS or windows is greater than MAXWINDOWS
Do how wide each window will be? (1-4)
    While wide is less than MINWIDE or wide is greater than MAXWIDE
Do how tall each window will be? (1-4)
    While tall is less than MINTALL or tall is greater than MAXTALL
Let s is 0 and s is less than stories increments s by 1 each iteration of the loop
    Display top row of story and walls
Let a is 0 and a is less than windows increments a by 1 each iteration of the loop
    Display windows borders, inner window borders, window borders, walls, and floor

OUTPUT

enter image description here

import java.util.Scanner;

public class BuildingAssign {

    public static void main (String [] args){

        int stories;
        int windows;
        int wide;
        int tall;
        final int MAXSTORIESHIGH= 4;
        final int MINSTORIESHIGH = 1;
        final int MAXWINDOWS = 4;
        final int MINWINDOWS = 1;
        final int MAXWIDE = 4;
        final int MINWIDE = 1;
        final int MAXTALL = 4;
        final int MINTALL = 1;

        Scanner in = new Scanner(System.in);

        do {
            System.out.print("How many stories high the building will be? (1-4): ");
            stories = in.nextInt();
        }while (stories < MINSTORIESHIGH || stories > MAXSTORIESHIGH);

        do {
            System.out.print("How many windows on each story? (1-4): ");
            windows = in.nextInt();
        }while (windows < MINWINDOWS || windows > MAXWINDOWS);

        do {
            System.out.print("How wide each window will be? (1-4): ");
            wide = in.nextInt();
        }while (wide < MINWIDE || wide > MAXWIDE);

        do {
            System.out.print("How tall each window will be? (1-4): ");
            tall = in.nextInt();
        }while (tall < MINTALL || tall > MAXTALL);

        for (int s=0; s<stories; s++)
        {
            System.out.println ("***********");        // printTopRowOfStory
            System.out.println ("*         *");        // printWalls

            for (int a=0; a<windows; a++)     
            {
                System.out.println ("* *** *** *");        // printWindowBorders   

                for (int t=0; t<tall; t++)          
                {                                   
                    System.out.println("* * * * * *");     // printInnerWindowBorders
                }       

                System.out.println("* *** *** *");         // printWindowBorders
                System.out.println("*         *");         // printWalls
            }
            System.out.println("***********");             // printFloor
        }
    }
}
edwardpark
  • 29
  • 1
  • 7

1 Answers1

0

You're setting your width variable (wide), but then you're never using it in any of the loops where you actually draw the buildings. So obviously you're window width is not going to be as you expect.

Many things, such as this line

System.out.println ("***********");        // printTopRowOfStory

and this line

System.out.println ("* *** *** *");        // printWindowBorders   

need to be chopped up, in order to compensate for the width.

Something like

//Print top row of story
for(int i = 0; i < wide; i++)  {
   System.out.println("**");  //Or however many...

//Print top window border
for(int i = 0; i < wide; i++)  {
   System.out.println("*");  //Or however many...
aliteralmind
  • 19,847
  • 17
  • 77
  • 108
  • Could you please explain more specific? What does it mean by the line should be chopped up? – edwardpark Feb 27 '14 at 03:18
  • Printing `System.out.println("* *** *** *)` for the top-window borders is wrong, because it does not print each window with the width as the user entered into the `wide` variable. So you'll have to create some loop or function that prints out *each window top* in order to compensate for this. – aliteralmind Feb 27 '14 at 03:24