Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Complete Chapter 9 exercises 5,6,7 as stated in text. Crucial things to notice:

ID: 3680282 • Letter: C

Question

Complete Chapter 9 exercises 5,6,7 as stated in text. Crucial things to notice:

1.See page 643 UML diagram, which requires at least 4 items in the Ticket base (abstract) class.

2. No Ticket objects can be created (read text), so the code like new Ticket(1); does not even compile.

In reality, we should connect this to a database to verify ticket numbers etc...., but that is outside the scope of inheritance.

I'm adding the following requirements, which do not violate anything stated in the text exercises, just adding. Please use this as a chance to "explore" the workings of inheritance, with rigorous adherence my specifications:

3. Your Ticket class is a chance to demonstrate how protected access works. REQUIRED: "protected String number;"

4. Let's assume the field "days" is an int, and that "price" is a double primitive type. REQUIRED "private int days" and "private double price"

5. Move all Ticket Class definitions to their own "tickets" package (NOTE: use EXACT import shown below), so protected access is enforced. Java has unique "package" access that allows public access for all classes within the same package (see Appendix C). Be certain the code below works, as I will add to that for testing (my grading). Note there is commented code that will not work if classes are structured correctly.

6. For Walkup tickets, implement setNumber and getNumber methods, but only for Walkup tickets

7. Allow constructors such as WalkupTicket("2") or using WalkupTicket(2) meaning overloaded constructors.

8. AdvanceTickets require additional constructor overload(s). For two argument constructor, assume the first is the number, and the second is the days, so AdvanceTicket(3,22) is ticket number 3 purchased 22 days in advance.

9. AdvanceTickets will always have "A" as the first character. Your constructor(s) must add "A" if needed, or do not when it's already there. Notice how AdvanceTickets can set the number field (inherit protected) but the client cannot set the number for AdvanceTickets.

10. NO System calls in any of these Ticket Classes, NO main() in Ticket Classes, just use main() below, plus add all the testing you think I would likely test.....

Exercises 644 Chapter 9 Inheritance and Interfaces items will have no discount, 0.0.) Currently the p charged full price, and item discounts are ign Implement a class called WalkupTicket to represent a walk-up event ticket. Walk-up tickets are also co ore number, and they have a price of $50. 7. Implement a class called Adva vance. An advance ticket is con- nceTicket to represent tickets purchased in ad structed with a ticket number and with the number of days in advance that the ticket was purchased. Advance tickets purchased 10 or more days before the event cost $30, and advance tickets purchased fewer than 10 days before the event cost $40. public double getprice() public double getDiscount 8. Implement a class called StudentådvanceTicket to represent tickets purcha 8. Implement a class called StudentAdvanceTicket to represent tickets purchased in advance by students. A student advance ticket is constructed with a ticket number and with the number of days in advance that the ticket was pur- chased. Student advance tickets purchased 10 or more days before the event cost S15, and student advance tickets purchased fewer than 10 days before the event cost $20 (half of a normal advance ticket). When a student advance ticket is printed, the String should mention that the student must show his or her student ID (for example, "Number: 17, Price: 15.0 (ID required)"). Define a class DiscountBill that extends c structor accepts a parameter for whether the reported for preferred customers. For examp s20 in discounts, then getTotal should rep items on which a customer is getting a nonz as a percentage of the original bill. Include count. Return 0.0 if the customer is not a pr 9. MinMaxAccount. A company has written a large class BankAccount with many methods including: public BankAccount (Startup s) public void debit (Debit d) public void credit(Credit c) public int getBalance () Constructs a BankAccount object using information in s Records the given debit Records the given credit Returns the current balance in pennies public DiscountBi11 (Employee clerk, boolean preferred) public int getDiscountCount() public double getDiscountAmoun public double getbiscoun Design a new class MinMaxAccount whose instances can be used in place of a bank account but include new behavior

Explanation / Answer

/**Ticket abstact class*/
//Ticket.java
public abstract class Ticket
{
  
   //private members of class
   private int number;
   private double price;
      
   //constructor that sets the number and price to 50
   public Ticket(int number)
   {
       this.number=number;
       //set price to 50
       price=50;
   }
  
   //Constructor to set the number and price
   public Ticket(int number, double price)
   {
       setNumber(number);
       setPrice(price);
   }
  
   //Set number
   public void setNumber(int number)
   {
       this.number=number;
   }
   //Set price
   public void setPrice(double price)
   {
       this.price=price;
   }
      
   //Return number
   public int getNumber()
   {
       return number;
   }
  
   //Return price
   public double getPrice()
   {
       return price;
   }
  
   //Returns the string description of the Ticket class object
   @Override
   public String toString()
   {      
       return "Number : "+number+", Price :"+price;  
   }  
}
--------------------------------------------------------------------------------------------
//WalkupTicket.java
//The class AdvanceTicket that extends the abstract class Ticket
public class WalkupTicket extends Ticket
{

   //Constructor to set number
   public WalkupTicket(int number)
   {
       //set number and price =50
       super(number, 50);      
   }  
   //Constructor to set number and price
   public WalkupTicket(int number, double price)
   {
       super(number, price);      
   }  
}
--------------------------------------------------------------------------------------------

//StudentAdvanceTicket.java
public class StudentAdvanceTicket extends Ticket
{
   private int days;

   public StudentAdvanceTicket(int number,int days)
   {      
       super(number);
       this.days=days;
      
      
       //set price of days<10
       if(days<10)
           setPrice(20);
       //set price of days>=10
       else if(days>=10)
           setPrice(15);
   }
  
   //Returns the string description of the Ticket class object
   @Override
   public String toString()
   {      
       return super.toString()+" (ID required)";
   }
  
}

--------------------------------------------------------------------------------------------
//AdvanceTicket.java
//The class AdvanceTicket that extends the abstract class Ticket
public class AdvanceTicket extends Ticket
{
   private int days;
  
   //Constructor that takes number and days as input arguments
   public AdvanceTicket(int number, int days)
   {
       super(number);
       this.days=days;
      
      
       //set price if days <10
       if(days<10)
           setPrice(40);
       //set price if days >=10
       else if(days>=10)
           setPrice(30);      
   }  
  
   @Override
   public String toString() {      
       return "Number : A"+getNumber()+", Price :"+getPrice()
               +", Days :"+days;
   }
}
--------------------------------------------------------------------------------------------
/**The java program TicketTester that tests the classes
* AdvancedTicket and WalkupTicket calling constructors
* and print the object desriptions.*/
//TicketTester.java
public class TicketTester {
    public static void main(String[] args) {
       // constructor overloaded
        AdvanceTicket AdvanceTicket(10, 20);

        System.out.println(one);   // output should be Number: A10, Price: 30.0, Days: 20
             
        WalkupTicket two = new WalkupTicket(2);
        // Create a field modifier to change the ticket number
        // modifies protected field, note overloaded
        two.setNumber(17);
        // methods and constructors are all overloaded
        System.out.println(two);
        // output should be Number: 17, Price: 50.0
    }
}
--------------------------------------------------------------------------------------------
Sample Output:
Number : A10, Price :30.0, Days :20
Number : 17, Price :50.0

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote