Advertisement
Guest User

Untitled

a guest
May 17th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class RegularTicket {
  2.     protected int id;
  3.     public int days;
  4.    
  5.     public RegularTicket(int days) {
  6.         days = this.days;
  7.         id = 1; //type of ticket
  8.     }
  9.    
  10.     public int getPrice() {
  11.         return 40;
  12.     }
  13.    
  14.     public int getId() {
  15.         return id;
  16.     }
  17.    
  18.     public int getDays() {
  19.         return days;
  20.     }
  21.    
  22.     public String toString() {
  23.         return "The ticket number is " + id + " and the price is" + getPrice() + ".";
  24.     }
  25.  
  26. }
  27.  
  28.  
  29. public class WalkupTicket extends RegularTicket {
  30.    
  31.     public WalkupTicket(int days) {
  32.         super(days);
  33.         id = 2;
  34.     }
  35.    
  36.     public int getPrice() {
  37.         return 50;
  38.     }
  39.    
  40.     public String toString() {
  41.         return "The ticket number is " + id + " and the price is" + getPrice() + ". This is a walkup ticket.";
  42.     }
  43. }
  44.  
  45.  
  46. public class AdvanceTicket extends RegularTicket {
  47.    
  48.  
  49.     public static final int deadline1 = 15;
  50.     public static final int deadline2 = 20;
  51.    
  52.     public AdvanceTicket(int days) {
  53.         super(days);
  54.         id = 3;
  55.     }
  56.  
  57.     public int getPrice() {
  58.         return (days > 19) ? deadline1 : (days > 9) ? deadline2 : super.getPrice();
  59.     }
  60.    
  61. }
  62.  
  63.  
  64. public class StudentAdvanceTicket extends AdvanceTicket {
  65.    
  66.     public StudentAdvanceTicket(int days) {
  67.         super(days);
  68.         id = 4;
  69.     }
  70.    
  71.     public int getPrice() {
  72.         return (days > 19) ? deadline1/2 : (days > 9) ? deadline2/2 : super.getPrice()/2;
  73.     }
  74.    
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement