/** * The BahnCard class for inlab 5. * * @author Devin Gray * @version February 18, 2016 **/ public class BahnCard { private int age; private boolean isStudent; public void setAge (int age) { this.age = age; } public void setStudent (boolean flag) { this.isStudent = flag; } /** * 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. */ public int bahnCard25Price (int desiredClass) { int cost = 0; if(desiredClass == 1) { cost = 110; } else //desiredClass == 2 { if(this.age < 19) { cost = 10; } else { cost = 55; } } return cost; } /** * 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. */ public int bahnCard50Price (int desiredClass) { int cost = 0; if(desiredClass == 1) { cost = 440; } else //desiredClass == 2 { cost = 220; } if(this.age <= 17 || this.age >= 60 || (this.isStudent && this.age < 27)) { cost = cost / 2; } return cost; } /** * The card costs 5900 euros for a first class card * and 3500 euros for a second class card. */ public int bahnCard100Price (int desiredClass) { int cost = 0; if(desiredClass == 1) { cost = 5900; } else //desiredClass == 2 { cost = 3500; } return cost; } }