Ticket Printer

16 points

In this program, you ask the user for the name of a concert she wants to attend, the date of the concert, her first name, middle initial and last name. Then the program prints up a ticket for her and creates a password that she can use to access her account on the system.

instance variables
The private instance variables that you'll need are: 6 String variables to hold the name of the band, the date of the concert, the concertgoer's first name, middle initial and last name, and a password that you will generate.

constructor TicketPrinter()
The constructor can be empty.

void getInfo()
Use 5 JOptionPane.showInputDialog(""); calls to find out the name of the band, the date of the concert, and the concertgoer's first name, middle initial and last name.

String generateName()
Concatenate the concertgoer's first name, middle initial and last name to create one String that holds her full name. Return this string.

String createPassword()
The user's password is his initials followed by a random number between 0 and 9999. For example, if the user's name is Dave A. Burns, his password might be DAB1234 or DAB457 or DAB98.
The static method 'Math.random()' generates a floating-point number between 0 and 1. Generate such a random number, using syntax like this: double num = Math.random();
Then multiply the result by 10000. Then cast the result to an integer and store the integer.
You need to 'pick off' the first letter of the user's first name and last name. Use the '.substring()' method to do this. The syntax might look like:
name = firstName.substring(someNumber, someNumber);
Then concatenate these three letters and the random integer you created to create the password. Return this string.

boolean checkName(String name)
Some people have bad credit and cannot be issued a ticket. In my version, these individuals do not qualify for a ticket: Jackie Barron, Alex Zambri, Michael Christie, Andre Antosiewicz and Brian Lussier. Create at least 5 Strings and assign names to them. Then declare a 'boolean' variable. A boolean variable can have 2 states: 'true' or 'false'. (Booleans are named for the 19th-century British mathematician George Boole, who invented a system of logic based on 0's and 1's.) Here is my syntax:
      boolean ok = true;
Then check 'name' (sent into the method) against each of the 5 names to see if the person who is trying to buy a ticket is not permitted to do so. (This will take place in an IF statement, or several IF statements.) If 'name' matches one of the people on the list, switch the boolean 'ok' to 'false'. You might want to use 'OR' in your IF statement; in Java 'OR' is expressed as '||'.
Return 'ok'.

void generateTicket(String name)
This method builds up the ticket by appending information to a String 'msg'. For example: String msg = "";
msg += "some info";
msg += "some more info";

And finally: JOptionPane.showMessageDialog(null, msg);

Output from one run of my program looks like this:

Steve Earle
November 22, 2002
Ticketholder's name: Dave D Daveson
Ticketholder's password: DDD8632

String modifyName(String name)
Many systems have a limit on how long a person's name can be, and this ticket system is similar. Decide what your limit is (I chose 20 characters). Then use '.length()' in an IF statement to see if the concertgoer's name is too long. If it is, use '.substring()' to shorten it to the acceptable length. Return this string.

void printMessage()
This method simply calls the 'messageBox()' method to notify the user that, because he has bad credit, he cannot buy a ticket. Here is how mine looks:

void setPassword(String p)
This method takes the String 'p' sent into it and assigns it to the instance variable that holds the password.

public static void main(String[] args)
In main(), after a TicketPrinter object is created, call 'getInfo()'. Call '.generateName()' and assign the result to a String. Call '.checkName()' and assign the result to a boolean variable 'ok'. Start an IF statement based on the value of 'ok'. If the concertgoer is OK, call '.modifyName()' and assign the result to a String. Call '.createPassword()' and assign the result to a String. Call '.setPassword(),' sending into the method the password that you just created. Finally, call '.generateTicket()'.
If the concertgoer is NOT OK, call '.printMessage()'.



You can download and run CompletedTicketPrinter.jar to see how your program will run when it is complete.


Starting Point

You can download to use as a starting point in writing your program.