I wrote this real quick so you can use as a guide. I'd suggest re-writing it completely so you understand what everything does. Also, there's no validation, which is required in ur assignment, so try to add that. If you need help with that, let me know.
Code
import java.util.Scanner;
public class House {
public static void main( String[] args ) {
int count = 0;
Scanner scanner = new Scanner( System.in );
System.out.println( "What is your name?" );
String name = scanner.nextLine( );
while ( true ) {
System.out.println( "Well " + name
+ ", welcome to my silly house drawing program." );
System.out.println( "Do you want me to draw a simple house for you? (yes/no)" );
boolean drawSimpleHouse = scanner.nextLine( ).equalsIgnoreCase( "yes" ) ? true
: false;
if ( !drawSimpleHouse ) {
break;
}
System.out.println( "Enter height and width of the house you want me to draw (must be even numbers):" );
String[] dimensions = scanner.nextLine( ).split( " " );
int height = Integer.parseInt( dimensions[0] );
int width = Integer.parseInt( dimensions[1] );
int middle = width % 2 == 0 ? (width / 2) - 1 : width / 2;
int heightRoof = middle + 1;
for ( int i = 0; i < heightRoof; i++ ) {
for ( int j = middle - i - 1; j >= 0; j-- ) {
System.out.print( " " );
}
if ( i == 0 ) {
System.out.print( "**" );
System.out.println( );
continue;
} else {
System.out.print( "/" );
for ( int k = 0; k < 2 * i; k++ ) {
System.out.print( " " );
}
}
System.out.print( "\\" );
System.out.println( );
}
for ( int i = 0; i < width; i++ ) {
System.out.print( "-" );
}
for ( int i = 0; i < height; i++ ) {
System.out.println( );
System.out.print( "|" );
for ( int j = 0; j < width - 2; j++ ) {
System.out.print( " " );
}
System.out.print( "|" );
}
System.out.println( "" );
for ( int i = 0; i < width; i++ ) {
System.out.print( "-" );
}
count++;
System.out.println( "\n" + name
+ " do you want me to draw another house for you (yes to continue)?" );
if ( !scanner.nextLine( ).equalsIgnoreCase( "yes" ) ) {
System.out.println( "Hope you like your "
+ (count > 1 ? count + " houses" : "house") + "!\nCome back soon "
+ name + "..." );
break;
}
}
}
}
This post was edited by labatymo on Oct 14 2015 09:57am