Results 1 to 4 of 4
  1. #1
    markious's Avatar
    markious is offline Member
    Join Date
    Oct 2008
    Posts
    27
    Rep Power
    0

    Default Can anyone help a little pls

    Java Code:
    class FestivalTicket{                                    //open class
         public static void main(String[]args){                //open main method
    
    
             String name = new String();
             int ticket_Num, party;
             double cost = 0;
             char again;
    
    
            System.out.println("Hello. Welcome to The Online Ticket Service. \n");
    
        do{
    
            for(int i=0; i < 40; i++)
    
            {
                System.out.print("**");
            }
    
    
    
            System.out.println("\nPease take a look at the following table to determine your ticket selection");
    
            System.out.println("\n\n_____________________________________________________________________");
            System.out.println("|Ticket Type                  | Price of one ticket| Selection Number|");
            System.out.println("|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|");
            System.out.println("|Day Ticket                   | 96.50euro          | 1               |");
            System.out.println("|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|");
            System.out.println("|Weekend Ticket With Camping  | 224.50euro         | 2               |");
            System.out.println("|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|");
            System.out.println("|Weekend Ticket NO Camping    | 177.50euro         | 3               |");
            System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
    
    
            for(int i=0; i < 40; i++)
    
            {
                System.out.print("**");
            }
    
    
    
    
    
                System.out.print("\n\nPlease enter your surname: ");
                 name = Keyboard.readString();
                 Keyboard.skipLine();
    
                 do{
                     System.out.print("\nWhich type of ticket would you like(1, 2, OR 3): ");
                    ticket_Num = Keyboard.readInt();
    
                        if(ticket_Num < 1 || ticket_Num > 3)
                            {
                                System.out.println("\nERROR: ONLY THE NUMBER 1 - 3 ARE ALLOWED ");
                            }
    
                }while(ticket_Num < 1 || ticket_Num > 3);
    
                do{
                     System.out.print("\nHow many people are in your party(max 4): ");
                     party = Keyboard.readInt();
    
                         if(party < 1 || party > 4 )
                             {
                                System.out.println("\nERROR: THERE IS A LIMIT OF 4 PEOPLE PER TICKET TRANSACTION ");
                            }
    
                }while(party < 1 || party > 4);
    
    
                    switch (ticket_Num) {
                            case 1:     System.out.println("\nFestival Ticket Type: Day Ticket");
                                        System.out.println("Surname:" + name);
                                        System.out.println("Number in party: " + party);
                                        cost = party * 96.50;
                                        System.out.println("Cost: " + cost + "euro"); break;
    
                            case 2:      System.out.println("\nFestival Ticket Type: Weekend Ticket With Camping");
                                        System.out.println("Surname:" + name);
                                        System.out.println("Number in party: " + party);
                                        cost = party * 224.50;
                                        System.out.println("Cost: " + cost + "euro"); break;
    
                            case 3:      System.out.println("\nFestival Ticket Type: Weekend Ticket NO Camping");
                                        System.out.println("Surname:" + name);
                                        System.out.println("Number in party: " + party);
                                        cost = party * 117.50;
                                        System.out.println("Cost: " + cost + "euro"); break;
    
                        }
    
    
                               System.out.print("\nProcess Another    Ticket?('y'/'n'): ");
                            again = Keyboard.readChar();
                            Keyboard.skipLine();
                            again = Character.toUpperCase(again);
    
    
              }while(again == 'Y');
    
    
    
         }                        //close main method
    
     }                            //close class
    OK i posted my program, its Just completed :D .. Compiles and runs fine.

    Only problem I have is in the Process another ticket part. I need to do an "if" statement for it, and wrap it in a "do while", so that only the characters Y and N will be allowed .. (not case sensitive)


    So i tried

    Java Code:
             do{
                                        ...................../rest of program here
    
    
                                             do{
                                       System.out.print("\nProcess Another Ticket?('y'/'n'): ");
                            again = Keyboard.readChar();
                            Keyboard.skipLine();
                            again = Character.toUpperCase(again);
    
                                                       if(again != 'Y' || again != 'N')
                                                            {
                                                                 System.out.print("ERROR: ONLY THE CHARS Y AND N ARE ACCPETED")
                                                             }
    
    
                                                }while(again != 'Y' || again != 'N');
    
    
              }while(again == 'Y');
    But when you do that. It doesnt stop loopin the Process another Ticket sentance :evil:

    Any help is much appreciated.


    BTW, I use a Keyboard.class to read in from the Keyboard, but any other method is fine .. Also I only suplied the whole program at the start cause Id find it easier to Read that way.

    Thanks in advance

    Mark
    Last edited by markious; 10-23-2008 at 03:37 PM.

  2. #2
    markious's Avatar
    markious is offline Member
    Join Date
    Oct 2008
    Posts
    27
    Rep Power
    0

    Cool

    Oh i just figured it out :D


    Java Code:
    while(again != 'Y' || again != 'N');
    That was my problem line

    Java Code:
    while(again != 'Y' && again != 'N');
    This seems to fix the problem, but im not sure how??

    If someone could explain that I would appreciate it,

    Thanks again,
    Mark

  3. #3
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    not equals y or not equals n

    Well, that's just about anything you can enter, isn't it? If it's y it's not n and so valid, since only one side of the expression needs to be valid, and vice versa.

    not equals y and not equals n

    Now when it is a y or an n, it is still valid for one side of the expression, but, because it's an and, it needs to be valid for both sides of the expression.

  4. #4
    markious's Avatar
    markious is offline Member
    Join Date
    Oct 2008
    Posts
    27
    Rep Power
    0

Posting Permissions

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