Anyone good with java coding?

mmallender.

Active member
so, i am working on an assignment and I am very stuck. I have to make "building" plans using numbers for the size of the plots, eg a house of size 1 would print +-+

|H|

+-+

and then a 2 would be a 2x2 version of that... the input method has to be a scanner,

input as: 2 H 2 A 2 B type of thing, and it would print:

+-+-+

|H|H|

+-+-+

|H|H|

+-+-+

+-+-+

|A|A|

+-+-+

|A|A|

+-+-+

+-+-+

|B|B|

+-+-+

|B|B|

+-+-+

anyone able to give me a hand?

 
i don't know java but the pseudo code would be something like this:

for each input letter

for the number of rows for that letter

print +

for the number of columns (same as above)

print out -

print out +

new line

print out |

for the number of columns (again)

print out letter

print out |

new line

I think that should work, hopefully ns doesn't mess up the spacing

 
yeah i have the actual output dialed, now i just need to make it work with a single line of inputs, and print different sized and letter coded "buildings"
 
for(int i = 0; i < num; ++i){

for(int j = 0; j < num; ++j){

system.print("+-");

}

system.println("+");

for(int j = 0; j < num; ++j){

system.print("|" + buildingChar);

}

system.println("|");

}

for(int j = 0; j < num; ++j){

system.print("+-");

}

^not sure if the for loops are java style, but I'm pretty sure that's how you print things in java. Its been a while. Notice the use of "print" vs "println".

as far as one line input, do a while loop checking for the end of the input stream, however you do that in java. Then first thing inside the while loop, read in an int, and a char. If java is anything like c++, the other input values will stay in the input stream until you start your while loop again and read in the next set.
 
that's what I would say, or you could do command line input. I don't know java though, only c++ so I can't really help that much
 
Back
Top