Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Practice Exam I - Computer Science I | CS 162, Exams of Computer Science

Material Type: Exam; Class: Computer Science I; Subject: Computer Science; University: Grand Valley State University; Term: Unknown 1989;

Typology: Exams

2009/2010

Uploaded on 02/24/2010

koofers-user-5io-1
koofers-user-5io-1 🇺🇸

10 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Name:________________________________
Due: Wednesday, 3 October
CS162
Computer Science I
Fall 2007
Practice Exam 1
Draft
The real test will look much like this one, but it will be shorter. I suggest taking this practice test under
“real” conditions (closed book, closed note) first, then going back and using your book and notes to
correct your answers. I will grade parts of this test for homework points, then give it back in time for
you to study from it. I strongly suggest that you limit your collaboration.
The real test will be Wednesday, 10 October.
Sample short answer essay questions: (you need not turn these in):
o Briefly explain the difference between classes and objects.
o Explain the difference between an actual parameter and a formal parameter
o What does “void” mean.
o Why are data types important?
Review the problems on javabat.
Review Quiz 1.
1a). Which of the following expressions evaluate to true?
!(4<5)
!false
(2>2) || ((4 == 4) && (1 < 0))
(2>2) || (4 == 4) && (1 < 0)
(34 != 33) && !false
1b). Evaluate the following expressions:
______ 3 + 4 * 5
______ 4 * 5 + 6
______ 35 % 7
______ 35 % 8
______ 5 + 4 % 2
______ 5 + 4 % 2 + 3
______ “C” + 3 + “PO”
______ 7 + 6 + “ Trombones” (Hint: Try it in BlueJ)
______ 27 / 4
______ 3 + 4 / 5
______ 3 + 4 / 5 + 6
pf3
pf4
pf5

Partial preview of the text

Download Practice Exam I - Computer Science I | CS 162 and more Exams Computer Science in PDF only on Docsity!

Name:________________________________ Due: Wednesday, 3 October

CS162 Computer Science I Fall 2007

Practice Exam 1

Draft

The real test will look much like this one, but it will be shorter. I suggest taking this practice test under “real” conditions (closed book, closed note) first, then going back and using your book and notes to correct your answers. I will grade parts of this test for homework points, then give it back in time for you to study from it. I strongly suggest that you limit your collaboration. The real test will be Wednesday, 10 October.

  • Sample short answer essay questions: (you need not turn these in): o Briefly explain the difference between classes and objects. o Explain the difference between an actual parameter and a formal parameter o What does “void” mean. o Why are data types important?
  • Review the problems on javabat.
  • Review Quiz 1. 1a). Which of the following expressions evaluate to true?
    • !(4<5)
    • !false
    • (2>2) || ((4 == 4) && (1 < 0))
    • (2>2) || (4 == 4) && (1 < 0)
    • (34 != 33) && !false 1b). Evaluate the following expressions: ______ 3 + 4 * 5 ______ 4 * 5 + 6 ______ 35 % 7 ______ 35 % 8 ______ 5 + 4 % 2 ______ 5 + 4 % 2 + 3 ______ “C” + 3 + “PO” ______ 7 + 6 + “ Trombones” (Hint: Try it in BlueJ) ______ 27 / 4 ______ 3 + 4 / 5 ______ 3 + 4 / 5 + 6

2). Complete the method below that calculates how many packages of hot dogs you will use completely and how many hot dogs will be left in an open package. Assume that half the people at your party (rounded down, if odd) will eat two hot dogs and the rest will eat only one. You may not use any of the methods in the Math package (e.g., Math.round). Remember how Java handles integer division. For example, if the input is 50, your output should look like this: You will empty 9 packages and have 5 hot dogs left over. class HotDogs { public void dogsAndBuns(int people_at_party) { final int DOGS_PER_PACKAGE = 8; // Your code here } // end method } // end class

4). Consider the Date class described below. Then, complete the isWeekend and testDateClass methods described below. Do not implement the constructor, getDayOfWeek, daysUntilChristmas, increment, or toString. class Date { public Date(int year, int month, int day) {…} public String getDayOfWeek() { … } public int daysUntilChristmas() { … } public increment(int numDays) { … }; public String toString() { … } } Write a method named isWeekend that takes no parameters and returns true if the current date is a Saturday or Sunday. Complete the method below according to the comments. This method is not part of the Date class. public void testDateClass() { // Create a Date object using appropriate literal values. // Call the Date object’s toString method and print the String returned. // If it’s Christmas print out “It’s Christmas! If it’s not Christmas, print “I can’t wait” and // use the daysUntilChristmas and increment methods together to set the date object // to Christmas. }

5). For each of the provided terms at the right, circle an example in the code and label it with the appropriate number. If the term does not apply anywhere in the code on this place, write “none”. Use pencil, plan ahead, and label neatly! Don’t obscure the code, you’ll need it later. class MysteryGamePlayer { private int redPoints; private int bluePoints; private int greenPoints; public MysteryGamePlayer(int a, int b) { redPoints = a; bluePoints = b; greenPoints = 0; } public void setGreenPoints(int c) { greenPoints = c; } public int getGreenPoints() { return greenPoints; } public int method1() { return redPoints - bluePoints + greenPoints; } public int method2(int p) { int m1val = method1(); return m1val + (p – 1)greenPoints; } public void modify(int d, int e) { redPoints = redPointsd; bluePoints = bluePoints*4; e = greenPoints; } public String toString() { return “rgb points: “ + redPoints + “ “ + bluePoints + “ “ + greenPoints; } } // end class MysteryGamePlayer 1 – string concatenation 2 – internal method call 3 – field declaration 4 - constructor 5 – conditional stmt 6 – equality operator 7 – formal parameter 8 – external method call 9 – return type 10 – actual parameter 11 – return value 12 – local variable 13 – comment

8). In the state of Georgia, you must use a car (or booster) seat until you are either (1) at least 7 years old, or (2) weigh at least 70 pounds. Complete the method carSeatRequired below that returns true if, and only if, the child described still needs a car or booster seat. For example:

  • carSeatRequired(8, 65) should return false
  • carSeatRequired(8, 75) should return false
  • carSeatRequired(6, 65) should return true
  • carSeatRequired(6, 75) should return false public static boolean carSeatRequired(int age, double weight) { } // end carSeatRequired