Unformatted text preview:

Final Exam Review Worksheet 1 How to use this document These are sample questions drawn from the topics that will most likely appear on your nal exam Please attempt to complete these questions without outside assistance Note responses to most of these will be provided during recitation and the last regular class session 1 1 A listing of topics Please examine the following list of topics and concentrate on these when preparing for your nal exams Note this list is not to be interpreted as exclusive In other words any topic from class instruction or previous midterms may be included on the nal exam Interfaces In particular make sure that you are comfortable with the Comparable interface Inheritance mechanisms Focus on Java extends operator and especially the use of super in the de nition of constructors on subclasses Overrides The single most important override for you to consider is the equals method Make sure that you know how to implement override this method in a variety of settings especially in subclasses Collections One and two dimensional arrays and the ArrayList class Note you will be provided with a table of operators for complex classes such as ArrayList these tables will provide you with acceptable methods and brief descriptions Data Structures You should be able to create and use Java s Stack to perform simple algorithms 1 2 Sample Questions 1 Given the following partial class de nitions public class Clock public class AlarmClock extends Clock public class StopWatch extends Clock a Draw an arrows and boxes diagram where diagrams name classes and arrows the extends relation that shows the relationship between these classes b De ne the default constructor for the StopWatch class so that it ensures that its parent s default constructor is called at the proper time during object creation Page 2 2 Suppose that the following modi cation is made to the de nitions from the previous question interface Timekeeper public class Clock implements Timekeeper public class AlarmClock extends Clock public class StopWatch extends Clock Write in the space provided along each part whether the declaration is valid or invalid a Timekeeper clock new AlarmClock b Clock clock new Timekeeper c Clock clock new AlarmClock d AlarmClock clock new Clock e Clock clock new StopWatch a b c d e Page 3 3 Given a non empty two dimensional array whose rows may contain a variable number of entries write the Hit method that returns true if any value found anywhere in the array is greater than or equal to target public static T Hit Comparable target Comparable table Page 4 4 For this question you will write the binaryString int integer method that takes an integer greater than or equal to 0 and prints a String that represents its binary value For example binaryString 5 prints the String 101 because 101 is the binary representation of the integer 5 You should use the following procedure to translate the base 10 integer into its base 2 equivalent assume that n is a non negative base 10 integer while n 0 compute the remainder of n 2 and push this into the stack update n to n 2 continue end while while stack is not empty pop the stack and print the object returned end while For example assume that n 5 then the following values will be pushed onto the stack Stack contents empty r n 2 n 5 2 r n 2 n 2 2 r 1 2 n 1 2 1 0 1 n n 5 n 0 Your procedure should then pop and print the contents of this stack until it is empty Your code must use Java s Stack E class and its push and pop methods You should also use the operator which determines the remainder of two integers 4 2 returns 0 but 1 2 returns 1 because 0 is the remainder when dividing 4 by 2 and 1 is the remainder of dividing 1 by 2 You will also need Java s operator that performs integer division Write this method on the next page Page 5 public static void binaryString int number Page 6 5 Examine the following partial de nitions public class Point private double x y public Point double x double y public Point Point otherPoint public class Vector private Point points public Vector int ofSize a Write the copy constructor for the Vector class so that it performs a deep copy of its parameter public Vector Vector other start here b Override the equals method on Vector so that two Vectors are equal when they have the same coordinates i e the same x and y values Page 7


View Full Document

UMD CMSC 131 - Final Exam Review Worksheet

Documents in this Course
Set #3

Set #3

7 pages

Exam #1

Exam #1

6 pages

Exam #1

Exam #1

6 pages

Notes

Notes

124 pages

Notes

Notes

124 pages

Load more
Download Final Exam Review Worksheet
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Final Exam Review Worksheet and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Final Exam Review Worksheet 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?