DOC PREVIEW
UVA CS 101 - CS 101 Final Exam

This preview shows page 1-2-3 out of 8 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS 101 Final Exam Fall 2004 Email Id ___________Name ______________________________________Pledged Page 1 of 8This exam is open book. Each question is worth 3 points.Page 1 ______ / 15Page 2 ______ / 15Page 3 ______ / 12Page 4 ______ / 18Page 5 ______ / 15Page 6 ______ / 9Page 7 ______ / 12Page 8 ______ / 6Total ______ / 100 (maximum is 102)1. Are you in CS101 or CS101E?2. Suppose n, j and k are previously defined and initialized integer variables. Write an expression thatmultiplies n times the quantity j plus k.3. Suppose n is a previously defined and initialized integer variable. Write an expression whose value isthe remainder of n when divided by 6.4. Write a definition for a local integer variable n whose initial value is 21.5. Suppose n and m are previously defined and initialized integer variables. Write a statement thatupdates the value of n to the value of m.CS 101 Final Exam Fall 2004 Email Id ___________Name ______________________________________Pledged Page 2 of 86. Suppose n is a previously defined and initialized integer variable. Write a statement that increases thevalue of variable n by 1, where the statement does not use the = operator.7. Write a statement that defines an integer constant named ZERO whose value is 0.8. Suppose n is a previously defined and initialized integer variable and that x is a previously defined andinitialized floating point variable. Write a statement that updates the value of n by assigning it theint-casted value of floating point value x.9. Suppose j and k are previously defined and initialized integer variables. Write an if statement thatsets variables j and k to 1 when j is less than k.10. Suppose j and k are previously defined and initialized integer variables. Write an if statement thatsets variables j and k to 1 when j is less than k; otherwise it sets j and k to 10.CS 101 Final Exam Fall 2004 Email Id ___________Name ______________________________________Pledged Page 3 of 811. Suppose j and k are previously defined and initialized integer variables. Write an if-else-if state-ment that sets variable j to 1, 2, or 3 respectively depending whether j is less than k, j equals k, orotherwise (i.e., j is greater than k).12. Write a for statement that iterates 1000 times using a previously undefined integer index variable i.Each iteration of the loop should display the current value of i (i.e., the values to be displayed are0 …999).13. Define a Scanner variable stdin associated with the standard input stream. Your definition shouldbe compatible with the latest version of Java.14. Define a Scanner variable stream associated the string represented by the previously defined andinitialized String variable s. Your definition should be compatible with the latest version of Java.CS 101 Final Exam Fall 2004 Email Id ___________Name ______________________________________Pledged Page 4 of 815. Suppose s and t are previously defined and initialized String variables. Write a code segment thatcauses t to represent the substring of s defined by indices 3 through 7 inclusive.16. Suppose input is a previously defined and initialized Scanner variable. Write a while loop thatiterates while the input stream associated with variable input has unread values. Each iteration of theloop should read and display the next int value.17. In TWENTY words or less how do the == operator and the equals() method typically differ.18. Define a new int[] variable data that references a list composed of the values 1, 2, and 3.19. Define a new int[] variable data that references a new array with ten elements.20. Update an initialized int[] variable data so that it references a new array with zero elements.CS 101 Final Exam Fall 2004 Email Id ___________Name ______________________________________Pledged Page 5 of 821. Suppose list is a defined and initialized int[] variable with 100 elements. Write a statement thatassigns 10 to the first element of list.22. Suppose list is a defined and initialized int[] variable with 100 elements. Write a statement thatassigns 10 to the last element of list.23. Suppose list is a defined and initialized int[] variable. Write a statement that displays the numberof elements represented by list.24. Suppose list is a defined and initialized String[] variable for an array with n elements andresult is a defined and initialized String variable. Write a code segment that causes result toreference a String whose value is a concatenation of the values represented by list.25. What is the output of the following program?public class Think {public void static mystery(int n) {n = 5;}public void static main(String[] args) {int n = 0;mystery(n);System.out.println("n = " + n);}}The output is n = __________CS 101 Final Exam Fall 2004 Email Id ___________Name ______________________________________Pledged Page 6 of 8The remaining questions deal with a class named Car. Class Car is to have the following privatedouble-valued attribute.• speed – current travelling rate of the car in miles per hour.Class Car is to also have the following public methods.• Car() – default constructor that configures a car to have a speed of 55 miles per hour.• Car() – specific constructor that has a single double-valued parameter v. The constructor config-ures the new car to have a speed of v.• howFar() – indicates how far the car will go if it travels for t hours, where t is its double-valuedparameter; i.e., the return value is the product of t and the speed attribute of the car.• getSpeed() – returns the current speed of the car.• setSpeed() – sets the current speed of the car to the value of its single double-valued parameterv.• clone() – returns a new Car with the same attribute of this car.• equals() – returns whether its Object-valued parameter value is a Car with the same speed asthis car.• toString() – returns a String representation of the car. The representation should consist of thevalue of the speed attribute within parentheses.26. Implement the Car default constructor using an assignment statement to configure the speed attribute.27. Implement the Car speed accessor getSpeed().28. Implement the Car speed mutator setSpeed().CS 101 Final Exam Fall 2004 Email Id ___________Name ______________________________________Pledged Page 7 of 829. Implement the Car specific constructor using a mutator to configure the speed attribute.30. Implement the toString() method for Car.31. Implement the Car default constructor so that it uses the specific


View Full Document

UVA CS 101 - CS 101 Final Exam

Documents in this Course
Classes

Classes

53 pages

Recursion

Recursion

15 pages

Iteration

Iteration

88 pages

PLEDGED

PLEDGED

6 pages

Objects

Objects

33 pages

PLEDGED

PLEDGED

11 pages

CS 101

CS 101

42 pages

Classes

Classes

83 pages

Iteration

Iteration

92 pages

Classes

Classes

186 pages

Classes

Classes

208 pages

Hardware

Hardware

21 pages

Arrays

Arrays

70 pages

Load more
Download CS 101 Final Exam
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 CS 101 Final Exam 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 CS 101 Final Exam 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?