final-sample-5-key

# Final-sample-5-key - CSE 143 Sample Final Exam#5 Key 1 Statement Output var1.one var1.two var1.three var2.one var2.two var2.three var3.one var3.two

This preview shows pages 1–3. Sign up to view the full content.

CSE 143 Sample Final Exam #5 Key 1. Statement Output var1.one(); var1.two(); var1.three(); var2.one(); var2.two(); var2.three(); var3.one(); var3.two(); var3.three(); var4.one(); var4.two(); var4.three(); ((Blue) var1).one(); ((Yellow) var1).two(); ((Red) var2).two(); ((Red) var2).three(); ((Object) var3).one(); ((Blue) var3).one(); ((Yellow) var3).two(); ((Green) var4).three(); ((Red) var4).one(); Blue 1 / Green 1 error Green 3 Blue 1 / Green 1 / Red 1 error Red 2 / Yellow 2 / Yellow 3 Blue 1 / Green 1 error Yellow 2 / Yellow 3 error error error Blue 1 / Green 1 error Red 2 / Yellow 2 / Green 3 error Yellow 2 Green 3 error 2. public class StudentTicket extends Ticket implements Comparable<StudentTicket> { private boolean honors; public StudentTicket(double price, boolean honors) { super(price, 14); this.honors = honors; } public double getPrice() { double price = super.getPrice() / 2; if (honors) { price = Math.max(0, price - 5.00); } return price; } public boolean isHonorStudent() { return honors; } public void setPromotionCode(String code) { super.setPromotionCode(code + " (student)"); } public int compareTo(StudentTicket other) { if (getPrice() != other.getPrice()) { return (int) Math.signum(getPrice() - other.getPrice()); } else { return getPromotionCode().compareTo(other.getPromotionCode()); } } }

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

View Full Document
3. Two solutions are shown. // for loop solution public void trimEnds(int k) { if (front != null) { // count size of list int size = 0; ListNode current = front; while (current != null) { current = current.next; size++; } if (size < 2 * k) { throw new IllegalArgumentException(); } else if (size == 2 * k) { front = null; } else { // remove k from front for (int i = 0; i < k; i++) { front = front.next; } // move past middle part current = front;
This is the end of the preview. Sign up to access the rest of the document.

## This document was uploaded on 12/17/2011.

### Page1 / 6

Final-sample-5-key - CSE 143 Sample Final Exam#5 Key 1 Statement Output var1.one var1.two var1.three var2.one var2.two var2.three var3.one var3.two

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

View Full Document
Ask a homework question - tutors are online