



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Material Type: Exam; Class: Computer Science I; Subject: Computer Science; University: Grand Valley State University; Term: Unknown 1989;
Typology: Exams
1 / 7
This page cannot be seen from the preview
Don't miss anything!
Name:________________________________ Due: Wednesday, 3 October
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.
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: