cheetsheet

cheetsheet - public class P6 { public static void...

Info iconThis 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. public Ticket(int num)
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.
Ask a homework question - tutors are online