Inlab 5: Decisions
Due: Friday 19 February at 6 pm
Purpose
The purpose of this in-lab is to introduce you to the concept of making
decisions in Java using the if statement.
Partners
This is an individual assignment, though collaboration (not
solution sharing) is allowed.
Preliminaries
Create a BlueJ project named Inlab5 on your lab computer.
Place the following files into this project:
Assignment
Train travelers in Germany can buy a one year discount card for
the train system called a BahnCard. There are three types of
BahnCards: a BahnCard 25 (provides the rider with a 25% discount),
a BahnCard 50 (provides the rider with a 50% discount),
and a BahnCard 100 (provides the rider with a 100% discount). In Germany,
one can travel first class or second class on the train system.
In this assignment, you are going to calculate how much a BahnCard
costs to buy, using the following rules.
- BahnCard25. The card costs 110 euros for a first class card
and 55 euros for a second class card. However, if the rider
is younger than 19, a second class card can be purchased for
10 euros.
- BahnCard50. The card costs 440 euros for a first class card
and 220 euros for a second class card. However, both of these
cards can be purchased at half price (220 for first class,
110 for second class) if any one
of the following three conditions applies:
- The person is seventeen years old or younger.
- The person is sixty years old or older.
- The person is a student who is younger than 27.
- BahnCard100. The card costs 5900 euros for a first class
card and 3500 euros for a second class card.
Note: do not modify the TestProgram.java file.
Submission
By Friday evening at 6:00 pm, submit the BahnCard.java file into the appropriate D2L dropbox folder. DO NOT SUBMIT .class files. Partial credit can be earned, but late assignments will not be accepted.
Grading - 10 points possible
- 8 points. You will lose 1 point for each of the 40 test cases that does
not produce the correct answer up to a maximum of 8 points. Output should look like this (output.txt).
- 1 point. Place an appropriate Javadoc comment at the top of the
BahnCard.java file. Use the code that
was demonstrated in lecture on Friday, February 12 as a model.
- 1 point. Place appropriate Javadoc comments preceding each
of the five methods in the BahnCard.java
file. Use the code that was demonstrated
in lecture on Friday, February 12 as a model.
Helpful Hint
There are three methods in the BahnCard class that you must
modify: bahnCard25Price, bahnCard50Price and bahnCard100Price.
Do the easiest method first, the second easiest method second
and the most difficult method last.