ASAP PLZ- Having problems with basic pattern input/output
Hey! I am new to this forum, and I am also new to java =).
I am writing a program that prompts a user to select 1 pattern out of 5. then the user needs to choose the number of lines he/she wants to display for instace:
(MENU)
PATTERN 5
1
12
123
1234
USER Selection : Pattern 5
Choose Number of Lines: 3
OUTPUT
Pattern 5
1
12
123
}
I have a basic code for a pyramid that deals with leading spaces etc.. but I don't have a clue how to use that method with my program
MY PROGRAM:
Code:
//Purpose: Displaying Patterns
//Input: User's selection
//Output: Messages
//Author; Fares
//Program: 4
//Date: 9/15/2009
//
import java.util.Scanner;
public class MyPatterns4{
public static void main(String[] args) {
// Declarations
Scanner scan = new Scanner(System.in);
String outputString;
int option = 1;
int lines;
// Paterns
String patternOne;
patternOne = "\n\t Pattern I \n\t 1 \n\t 12 \n\t 123 \n\t 1234 \n\t 12345 \n\t 123456";
String patternTwo;
patternTwo= "\n\t Pattern II \n\t 123456 \n\t 12345 \n\t 1234 \n\t 123 \n\t 12 \n\t 1";
String patternThree;
patternThree = "\n\t Pattern III \n\t 1 \n\t 21 \n\t 321 \n\t 4321 \n\t 54321 \n\t 654321";
String patternFour;
patternFour = "\n\t Pattern IV \n\t 123456 \n\t 12345 \n\t 1234 \n\t 123 \n\t 12 \n\t 1";
String patternFive;
patternFive = "\n\t Pattern V \n\t 1 \n\t 12 \n\t 123 \n\t 123456 \n\t 123 \n\t 12";
// Prompt the user to select a pattern
outputString = "------------------------------------\n\t1 Display Pattern I\n\t2 Display Pattern II\n\t"
"3 Display Pattern III\n\t4 Display Pattern IV\n\t"
"5 Display Pattern V\n\t" "6 Display All Patterns\n\n\n\t" "0 Quit\n\n\n";
System.out.println(outputString);
System.out.print("\tEnter your selection: ");
option = scan.nextInt();
// Keep reading data until the user enters 0
while (option !=0){
while (option == 6) {
outputString = "\nChoose another selections!\n";
System.out.println(patternOne);
System.out.println(patternTwo);
System.out.println(patternThree);
System.out.println(patternFour);
System.out.println(patternFive);
System.out.println(outputString);
outputString = "--------------------------------------------------\n\t1 Display Pattern I\n\t2 Display Pattern II\n\t"
"3 Display Pattern III\n\t4 Display Pattern IV\n\t"
"5 Display Pattern V\n\t" "6 Display All Patterns\n\n\n\t" "0 Quit\n\n\n";
System.out.println(outputString);
System.out.print("\tEnter your selection: ");
option = scan.nextInt();
}
while (option != 0 && option !=6) {
System.out.print("\tEnter number of lines: ");
lines = scan.nextInt();
if (lines < 1 || lines > 6) {
System.out.println("\tYou must enter a number from 1 to 6");
System.out.print("\tEnter number of lines: ");
lines = scan.nextInt();
while (lines < 1 || lines > 6) {
System.out.println("\tYou must enter a number from 1 to 6. The program will now end.");
System.exit(0);}
}
switch (option) {
case 1: // write the code to display Pattern I here
outputString = "\n Choose another selection! \n";
System.out.println(patternOne);
System.out.println(outputString);
break;
case 2: // write the code to display Pattern II here
outputString = "\nChoose another selection!\n";
System.out.println(patternTwo);
System.out.println(outputString);
break;
case 3: // write the code to display Pattern III here
outputString = "\nChoose another selection!\n";
System.out.println(patternThree);
System.out.println(outputString);
break;
case 4: // write the code to display Pattern IV here
outputString = "\nChoose another selection!\n";
System.out.println(patternFour);
System.out.println(outputString);
break;
case 5: // write the code to display Pattern V here
outputString = "\nChoose another selection!\n";
System.out.println(patternFive);
System.out.println(outputString);
break;
case 6: // the code to display all paterns
outputString = "\nChoose another selections!\n";
System.out.println(patternOne);
System.out.println(patternTwo);
System.out.println(patternThree);
System.out.println(patternFour);
System.out.println(patternFive);
System.out.println(outputString);
break;
default: outputString = "\nInvalid Selection\n";
System.out.println(outputString);
break;
}// end of switch
outputString = "------------------------------------\n\t1 Display Pattern I\n\t2 Display Pattern II\n\t"
"3 Display Pattern III\n\t4 Display Pattern IV\n\t"
"5 Display Pattern V\n\t" "6 Display All Patterns\n\n\n\t" "0 Quit\n\n\n";
System.out.println(outputString);
System.out.print("\tEnter your selection: ");
option = scan.nextInt();
} }// end of while loop
}// end of main method
}// end of class