fa09M1 - CS 307 – Midterm 1 – Fall 2009 1 Points off 1...

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

View Full Document Right Arrow Icon

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

View Full Document Right Arrow Icon

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

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS 307 – Midterm 1 – Fall 2009 1 Points off 1 2 3A 3B 4A 4B Total off Net Score CS 307 – Midterm 1 – Fall 2009 Your Name____________________________________ Your UTEID __________________________________ Circle yours TA’s name: Oswaldo Rashid Swati Instructions: 1. Please turn off or silence your cell phones. 2. There are 4 questions on this test. 3. You have 2 hours to complete the test. 4. You may not use a calculator or any other electronic devices while taking the test. 5. When code is required, write Java code. 6. When writing a method, assume the preconditions of the method are met. 7. When writing a method you may add helper methods if you wish. 8. When you complete the test show the proctor your UTID and give them the test and any scratch paper. Please leave the room quietly. 1. (2 points each, 30 points total) Short answer questions. Place your answers on the attached answer sheet. For code sample state the output. If the code would cause a syntax error answer "syntax error". If it would cause a runtime exception answer "exception". If it would result in an infinite loop answer "infinite loop". A. What is output by the following code? int list1 = {4, 2, -1}; int list2 = new int[3]; list1[1]++; list2 = list1; list1[1]++; System.out.println(Arrays.toString(list2)); // prints out elements B. What is output by the following code? int list3 = {2, 1, 5, 1}; System.out.println( list3[ list3[0] ] ); CS 307 – Midterm 1 – Fall 2009 2 For questions C – N consider the following classes and interfaces. public interface TotalPoints{ public int getPoints(); } public class WinLossRecord implements TotalPoints{ private int wins; private int losses; public WinLossRecord(){ this(0, 0); } public WinLossRecord(int ws, int ls){ wins = ws; losses = ls; } public void win(){ wins++; } public void lose(){ losses++; } public int getWins(){ return wins; } public int getLosses(){ return losses; } public int getPoints(){ return wins * 2; } } public class WinLossRecordWithTies extends WinLossRecord{ private int ties; public WinLossRecordWithTies(){ ties = 0; } public WinLossRecordWithTies(int ws, int ls, int ts){ super(ws, ls); ties = ts; } public void tie(){ ties++; } public int getTies(){ return ties; } public int getPoints(){ return getWins() * 3 + getTies(); } } CS 307 – Midterm 1 – Fall 2009 3 C. State if the following declarations are valid or invalid (meaning they cause a syntax error). 1 point each TotalPoints t1 = new TotalPoints(); Object obj1 = new WinLossRecord(); D. State if the following declarations are valid or invalid (meaning they cause a syntax error). 1 point each WinLossRecordWithTies w2 = new Object(); TotalPoints t2 = new WinLossRecordWithTies(3, 2, 3); E. State if the following declarations are valid or invalid (meaning they cause a syntax error)....
View Full Document

{[ snackBarMessage ]}

Page1 / 17

fa09M1 - CS 307 – Midterm 1 – Fall 2009 1 Points off 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