final-sample-5 - CSE 143 Sample Final Exam #5 1....

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 143 Sample Final Exam #5 1. Inheritance and Polymorphism . Consider the following classes ( System.out.println has been abbreviated as S.o.pln ): public class Blue extends Green { public void one() { System.out.println("Blue 1"); super.one(); } } public class Red extends Yellow { public void one() { super.one(); System.out.println("Red 1"); } public void two() { System.out.println("Red 2"); super.two(); } } public class Yellow extends Blue { public void two() { System.out.println("Yellow 2"); } public void three() { two(); System.out.println("Yellow 3"); } } public class Green { public void one() { System.out.println("Green 1"); } public void three() { System.out.println("Green 3"); } } The following variables are defined: Green var1 = new Blue(); Green var2 = new Red(); Blue var3 = new Yellow(); Object var4 = new Green(); In the table below, indicate in the right-hand column the output produced by the statement in the left-hand column. If the statement produces more than one line of output, indicate the line breaks with slashes as in "a / b / c" to indicate three lines of output with "a" followed by "b" followed by "c". If the statement causes an error, fill in the right-hand column with the phrase "error" to indicate this. Statement var1.one(); var1.two(); var1.three(); var2.one(); var2.two(); var2.three(); var3.two(); var3.three(); var4.one(); ((Blue) var1).one(); ((Yellow) var1).two(); ((Red) var2).three(); ((Yellow) var2).two(); ((Green) var4).three(); ((Yellow) var4).two(); Output ________________________ ________________________ ________________________ ________________________ ________________________ ________________________ ________________________ ________________________ ________________________ ________________________ ________________________ ________________________ ________________________ ________________________ ________________________
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2. Inheritance and Comparable . You have been asked to extend a pre-existing class Ticket that represents a ticket to attend an on-campus event. A ticket has a price and also stores how many days early the ticket was bought (how many days before its event takes place). Some tickets have "promotion codes" that can allow special access and benefits for the ticket holder.
Background image of page 2
The Ticket class includes the following members: Member Description private double price private int daysEarly private String promotionCode private data of each ticket public Ticket (double price, int daysEarly) constructs a ticket with the given price, purchased the given number of days early, with no promotion code public int getDaysEarly () returns how many days early the ticket was bought public double getPrice () returns the ticket's price public String getPromotionCode () returns the ticket's promotion code ( "" if none) public void setPromotionCode (String code) sets the ticket's promotion code to the given value (throws an exception if null is passed) public String toString () returns a string representation of the ticket
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 8

final-sample-5 - CSE 143 Sample Final Exam #5 1....

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online