2011-09-29 12:55:46 UTC
Your program should present a canvas to the user, and then repeatedly prompt the user for characters to add to the canvas, and where to add them.
To initialize the canvas, the program should ask how large of a canvas (how many characters wide and high) the user wants.
It should loop repeatedly, and each time through the loop it should:
Ask the user if they are finished painting. If so, the program should exit.
Ask the user which part of the canvas they would like to fill in.
Ask the user what letter or character they would like to paint in that part of the canvas.
Update the canvas, as per the user's instructions.
"Re-draw" (print to the screen) the updated version of the canvas.
If the user enters an incorrect part of the canvas (outside the range of possible values), the program should not crash or exit. It should print an error message, and then continue to prompt for a valid part of the canvas
and this is what I have so far:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner keys = new Scanner(System.in);
System.out.println("Please enter the height of your canvas");
int height = keys.nextInt();
System.out.println("Please enter the width of your canvas");
int width = keys.nextInt();
char[][]Canvas = new char[height][width];
for(int i=0; i < height; i++)
{
for(int j=0; j < width; j++)
Canvas[i][j] = ' ';
}
int row = 0;
while(row
if(row==0 || row ==height-1)
{
for(int col = 0; col
System.out.print("*");
}
}
else
{
System.out.print("*");
for(int col=0; col < width; col++){
System.out.print(Canvas[row][col]);
}
System.out.print("*");
}
System.out.println();
row++;
}
System.out.println("Do you want to continue Picasso? (Y/N)");
String answer = keys.next();
{
if (answer.equalsIgnoreCase("N"))
{
System.out.println("Adios!");
System.exit(0);
}
else
{
System.out.println("What position would you like it in?"
+ " Enter the x displacement, followed by a space"
+ " and then the y displacement");
int x = keys.nextInt();
int y = keys.nextInt();
System.out.println("What character would you like to use?"
+ " Enter it now: (Pick a good one!)");
String s = keys.next();
Canvas[x][y] = s.charAt(0);
row = 0;
while(row
if(row==0 || row ==height-1)
{
for(int col = 0; col
System.out.print("*");
}
}
else
{
System.out.print("*");
for(int col=0; col < width; col++){
System.out.print(Canvas[row][col]);
}
System.out.print("*");
}
System.out.println();
row++;
}
}
I can't get it to continue looping to ask the question about resuming or keep printing what the user has already inputted. HELP PLEASEEE!