Results 1 to 4 of 4
  1. #1
    ZetaPunk is offline Member
    Join Date
    Sep 2009
    Posts
    2
    Rep Power
    0

    Default 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:
    Java 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
    Last edited by ZetaPunk; 09-22-2009 at 05:10 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  3. #3
    ZetaPunk is offline Member
    Join Date
    Sep 2009
    Posts
    2
    Rep Power
    0

    Default

    We can't cross post? Is that a wrong-doing in forums? I thought asking multiple resources was a smart thing to do. I found my problem and its fixed.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Replies: 1
    Last Post: 08-04-2009, 01:48 PM
  2. Single XSD Creation for input/output
    By lavanya82 in forum XML
    Replies: 0
    Last Post: 03-13-2009, 01:02 PM
  3. problems with java code! (very new - need help asap!)
    By sumkindafreek in forum New To Java
    Replies: 1
    Last Post: 01-07-2009, 06:00 AM
  4. Basic keyboard input and edit
    By BHCluster in forum New To Java
    Replies: 18
    Last Post: 08-09-2008, 12:52 AM
  5. array problems need your help ASAP!
    By notherand in forum New To Java
    Replies: 1
    Last Post: 06-29-2008, 09:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •