Laboratory 4: Graded Lab

February 21, 22, 2006

Bring your Java, Java, Java text to the laboratory.

You may use the textbook, your notes, your listings from previous labs, and Java documentation online.

Objectives

The objectives of this laboratory are
  1. to evaluate your comprehension of Java fundamentals.
This lab will be graded on a 100 point scale. You will be graded on the following criteria:

Problem statement

Design and implement a class named SeasonTicket. This class will have two instance variables, one for the name of the team, with possible values being "Yankees" or "Red Sox", and the other being the price of the season ticket, with possible values being integers such as 5000 or 7500. The class should have a constructor method that allows the values for the team name and price to be set when a new object is constructed.

The class should have accessor methods, getTeam() and getPrice() that get the values of the two instance variables when they are called. It should also have a method named calculateQuantityPrice() that returns an integer giving the total price for a quantity of tickets. This method will take one parameter, an integer representing the number of tickets being purchased. Calculating the total price requires a simple multiplication operation: quantity times price. The multiplication symbol in Java is the asterisk (*).

Define a second class named BuySeasonTicket that contains a main() method that will be used to test the correctness of your implementation of the SeasonTicket class. As in last week's lab, the main() method will use a KeyboardReader object to prompt the user and to read keyboard input from the user.

The main() program should create two SeasonTicket objects, one for the "Yankees", whose season ticket costs $7500, and one for the "Red Sox", whose ticket cost $5000. Take care with the spelling of the team names. It should prompt the user for the team name and for the quantity of tickets they want to purchase. It should then report the total sales price.

Design your algorithm so that it produces exactly output shown here, including all the line breaks and punctuation. This listing shows two separate runs and the user's input is shown in bold face:


This program will help you purchase Yankees or Red Sox season tickets.
What team do you want, Yankees or Red Sox? Yankees
Yankees season tickets cost $7500 per ticket.
How many tickets do you want? 5
That will be a total of $37500


This program will help you purchase Yankees or Red Sox season tickets.
What team do you want, Yankees or Red Sox? Red Sox
Red Sox season tickets cost $5000 per ticket.
How many tickets do you want? 10
That will be a total of $50000

Note that the program must decide based on the user's input whether to quote the price of the Yankees or Red Sox ticket. Note that the program is getting information from the two SeasonTicket objects to report the ticket's price and the total price for the quantity of tickets.

UML Diagram

Before beginning to program, draw a complete UML diagram for this problem, showing both the SeasonTicket and BuySeasonTicket classes. Have your diagrams checked by the TA or instructor before you start programming. These will be handed in and graded as part of the lab.

Pointers/Suggestions

Hand In.

Before handing in your programs, be sure to document your source code.

Have your work checked by the laboratory instructor or TA. Print out and hand in copies of your SeasonTicket.java and BuySeasonTicket.java files.

You're done. Great work!