ITEC 120 Back to Assignment index page
   
Assignment 5 - Baseball cards
Submit your program to the RU11 in your folder on neelix.

Description: 

Tommy found a box of baseball cards in the attic. He decided he would keep the most valuable one of each unique card, and sell all the duplicates. He went through the whole box and catalogued each card, listing the player's name, team, year, condition of the card, and the value of the card.

You will write a program which will read the data, and decide which cards to keep, and which to sell.

First design a class to represent a baseball card. A baseball card has 5 pieces of instance data:

Decide what methods the BaseballCard class should have, and write them. You may find you need to add a method later.

Next write a program which reads baseball cards from a file. There will be one card per line, and each line will have 5 pieces of data, separated by commas. A line from the file looks like this:

Robin Yount,Brewers,1988,Excellent,1.50

Keep two arrays in your program, one for the cards to keep, and one for the cards to sell. When you read a new card from the file, you'll have to check to see if you already have one in the keeper array. If so, keep the most valuable one, and put the other one in the to sell array. If it is not already in the keeper array, put it in.

Once you've read all cards in, and put in one array or the other, print out each card in the keeper array, and show the total value of all kept cards. Then print out all the cards in the to sell array, and show the total value of the cards to sell.

Here is output for the cards in the file in.dat:

Program displays: Enter the name of the input file:

User enters:

in.dat

Program displays:

~~~~~~~~~~~~~~~~~~~~~~~ Keepers ~~~~~~~~~~~~~~~~~~~~~~~~
Sandy Alomar    Indians     1989    Excellent    $2.50
Robin Yount     Brewers     1987    Good         $2.00
Bronson Arroyo  Pirates     1998    Poor         $1.00
Tom Seaver      Mets        1969    Good         $40.00
Robin Yount     Brewers     1993    Mint         $0.80
Carlos Baerga   Indians     1990    Excellent    $0.25
Hideo Nomo      Dodgers     1996    Good         $0.75
Pete Rose       Reds        1971    Mint         $30.00
Robin Yount     Brewers     1989    Excellent    $0.40
Mike Schmidt    Phillies    1995    Mint         $1.00
Robin Yount     Brewers     1988    Excellent    $1.50
Tom Seaver      Mets        1973    Mint         $15.00
Robin Yount     Brewers     1978    Good         $12.00
Tom Seaver      White Sox   1984    Mint         $2.00
Sandy Alomar    Indians     1990    Fair         $2.00

The total value of kept cards is: $111.20

~~~~~~~~~~~~~~~~~~~~~~~ To Sell ~~~~~~~~~~~~~~~~~~~~~~~~
Robin Yount     Brewers     1987    Fair         $0.20
Sandy Alomar    Indians     1989    Mint         $0.50
Robin Yount     Brewers     1987    Poor         $0.25
Pete Rose       Reds        1971    Good         $18.00
Robin Yount     Brewers     1988    Good         $0.90
Mike Schmidt    Phillies    1995    Excellent    $0.75
Pete Rose       Reds        1971    Fair         $12.00
Tom Seaver      Mets        1973    Excellent    $12.00
Robin Yount     Brewers     1987    Fair         $0.25
Robin Yount     Brewers     1978    Poor         $8.50
Robin Yount     Brewers     1989    Good         $0.30
Robin Yount     Brewers     1988    Good         $0.25

The total value of cards to sell is: $53.90