ITEC 120 LAB 11 Back to Lab index page

Lunchcard

You will write a Java class to represent a lunchcard (much like your RU id).

Lunchcard

- name : String
- meals : int

+ Lunchcard ( String owner )
+ Lunchcard ( String owner, int numofmeals )

+ swipe ( ) : int
+ swipe (int numofmeals) : int
+ buy ( ) : int
+ buy ( int numofmeals ) : int
+ toString ( ) : String

Write a driver program which tests all of these methods. The purpose of this program is just to test the methods in your class file. (You don't need to get any info from the user, just make up all the data in your driver program.) Make println statements to let you know what the program is doing.

A sample run will look like this:

Two lunchcards created.
Ethel Mertz- Meals remaining: 0    Fred Mertz- Meals remaining: 12

Ethel buys 25 meals
Ethel Mertz- Meals remaining: 25   Fred Mertz- Meals remaining: 12

Fred's card swiped once
Ethel Mertz- Meals remaining: 25   Fred Mertz- Meals remaining: 11

Swiped 4 meals from Ethel's card.
Ethel Mertz- Meals remaining: 21   Fred Mertz- Meals remaining: 11

Fred buys 10 meals.
Ethel Mertz- Meals remaining: 21   Fred Mertz- Meals remaining: 21

Swiped 7 meals from Fred's card
Ethel Mertz- Meals remaining: 21   Fred Mertz- Meals remaining: 14

Swiped Ethel's card 5 times
Ethel Mertz- Meals remaining: 16   Fred Mertz- Meals remaining: 14


Once you have your program working, show your lab to the Peer Instructor to be checked off.