cheetsheet - public class P6 public static void main(String...

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
public class P6 { public static void main(String [] args) { Ticket ticket1 = new Ticket(1); System.out.println(ticket1.printTicket() + "\n"); AdvanceTicket ticket2 = new AdvanceTicket(2,9); System.out.println(ticket2); StudentTicket ticket3 = new StudentTicket(3,15); System.out.println(ticket3); StudentTicket ticket4 = new StudentTicket(4,5); System.out.println(ticket4); Ticket ticket5 = new Ticket(ticket1); System.out.println(ticket1.equals(ticket5)); AdvanceTicket ticket6 = new AdvanceTicket(new AdvanceTicket(2,9)); System.out.println(ticket6.equals(ticket2)); System.out.println(ticket3.equals(new AdvanceTicket(3,15)) + "\n"); Ticket [] arrayOfTickets = new Ticket[3]; arrayOfTickets[0] = new Ticket(10); arrayOfTickets[1] = new AdvanceTicket(15,30); arrayOfTickets[2] = new StudentTicket(20,5); for(int i = 0; i < arrayOfTickets.length; i++) System.out.println(arrayOfTickets[i]); Ticket[] anotherArray = new Ticket[arrayOfTickets.length]; for (int i=0; i<anotherArray.length; i++) { anotherArray[i]= arrayOfTickets[i].clone(); } for(int i = 0; i < anotherArray.length; i++) System.out.println(anotherArray[i].equals(arrayOf Tickets[i])); } } // This is the parent class for tickets that sets the price and ticketnumber class Ticket { protected final int price = 50; protected int ticketNumber; //default constructor public Ticket() { ticketNumber = 0; } //Precondition: tk must be a valid ticket (the number's validity is checked in setNumber) //This is the main constructor.
Image of page 1
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern