Help would be apprecited!
How do I make it so that at the end of this programme you have the option to go again
Code:
import java.util.Scanner;
public class Mandatory {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner keyboard = new Scanner(System.in);
int Mouth, Nose = 0, Eyes,Hair = 0;
String MouthString, NoseString = null, EyesString = null, HairString = null;
System.out.println("Automated Sketch Artist:\n\tPlease make your selections based on the numbers with each \"Style\": ");
do
{
System.out.println("\nHairstyle = 1 Bald, 2 Crew-cut, 3 Curly, 4 Wearing a hat? ");
while (! keyboard.hasNextInt())
{
System.out.print("Invalid - Try again. Please enter the number which goes with your hairstyle selection. ");
keyboard.nextLine();
}
Hair = keyboard.nextInt();
keyboard.nextLine();
}
while (Hair <= 0 || Hair >4);
switch (Hair) {
case 1: HairString = ""; break;
case 2: HairString = "----------\n----------"; break;
case 3: HairString = "??????????"; break;
case 4: HairString = " ______\n/______\\"; break;}
do
{
System.out.println("Eyes = 1 Beedy, 2 Cross-eyed, 3 Glasses, 4 closed? ");
while (! keyboard.hasNextInt())
{
System.out.print("Invalid - Try again. Please enter the number which goes with your eyes selection. ");
keyboard.nextLine();
}
Eyes = keyboard.nextInt();
keyboard.nextLine();
}
while (Eyes <= 0 || Eyes >4);
switch (Eyes) {
case 1: EyesString = " . . "; break;
case 2: EyesString = "(>) (<) "; break;
case 3: EyesString = " __ __\n| |-| |\n -- -- "; break;
case 4: EyesString = " __ __"; break;}
System.out.println(HairString);
System.out.println();
System.out.println(EyesString);
System.out.println();
System.out.println(NoseString);
System.out.println(MouthString);
System.out.println();
}
}
I've cut out some of the code to make it shorter, wont effect answers.. Help please!
Re: Help would be apprecited!
I've removed the duplicate of this thread - I hope nothing is lost. If so, just say. Your thread didn't show up at once because it was "awaiting moderation". (No, I have no idea why some threads are held up like this. For some reason you're put on the "group W bench" - maybe you have unpaid parking fines or something...)
Quote:
How do I make it so that at the end of this programme you have the option to go again
Yes, that's easy.
Code:
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
String resp;
do {
run();
System.out.println("Again?");
resp = keyboard.nextLine();
} while(resp.equalsIgnoreCase("Y"));
}
private static void run() {
// your code here
}
The point is that main() is intended to do one thing only: call another method over and over again. You could apply this principle of breaking things up into multiple methods to the rest of your program. For instance you have a hairstyle do-while loop that goes round and round until it gets an int from 1->4. Why not have a separate method that does this and returns the (validated) value that was input? If methods do as little as possible it's easier to see what's happening.
Re: Help would be apprecited!
Thanks for the reply and sorry for the duplicate.. I just assumed I didn't post it right when it didn't show up right away.
That has worked perfectly for what I needed!
Re: Help would be apprecited!