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!

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
        }
    }
}

Either
Use an inner loop that prints the correct number of asterisks or blanks for each window
or
Have a long-enough string initialised to lots of asterisks and print a substring of the right length from that

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.