CS 178 Programming with Multimedia Objects
Fall 2004 |
||||||||||||||||||||||||||||||||||||||||
Readings and Practice Problems for the Final Exam (with Solutions)
Prepared by: Aditya Mathur Final Exam schedule: Dec 15, 2004. 10:20am-12:20pm Room: TBA Latest update: Dec 12, 2004 |
||||||||||||||||||||||||||||||||||||||||
Readings for the Final Exam | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
Part A: Closed Book. 10 multiple choice questions. Total: 20 points. Time: allowed: 30 minutes. It will cover the entire course material listed in the table above. No exceptions.
Part B: Open Book. Total: 80 points. Time allowed: 90 minutes.Two questions. Question 1: You will be asked to code a given algorithm into a Java applet. This and the next question will require a good understanding of all material covered during the class, labs, and projects. Question 2: You will be asked to write Java code for a class. The class will have a few constructors, private and public methods, private and public variables, and static variables. The practice problems below should help you prepare to deal with this question. Sample question for Part A: geneName is an array of charS. Which of the following statements converts genename into an object g of type String? (a) String g=new String("geneName"); (b) String g=geneName; (c) String g=new String(geneName); (d) String g=new char(geneName); Preparation for Part B:
3. Array manipulation: Consider the following arrays:
Write a method findTime(double speed) that sets travelTime[j] to the time required for a spaceship to travel from the earth to planetName]j]. Assume that distanceFromEarth[j] is the distance in miles from the earth to planetName[j]. The argument to findTime( ) is the speed in miles/hr of the spaceship. Solution: This is a simple problem. Use a loop for call findTime as many times as there are planets in the planetName array. Finding travel time given distance and speed is trivial. 4. Array manipulation. Consider the following two declarations:
Write a method named arrayReverse() that reverses the elements in array x into array y. For example, if array x is: x={"helium", "hydrogen", "iron", "uranium"} then the array y should be y={"uranium", "iron", "hydrogen", "helium"} 5. Constructing your own class. (a) Write a class named Dog. It has the following constructors:
(b) The Dog class provides the following methods: public void setBreed(String breed) // Sets the breed of a Dog object. public void setWeight(double weight) // This sets the weight of a Dog object. public double getWeight() // Returns the weight of the Dog object. public setOwner(String owner) // This sets the owner of a Dog object. public String getOwner() // Returns the name of the owner of the Dog object. public String getBreed(); // Returns the breed of the dog object. public String getName() // Returns the name of the dog object. (c) Write an applet named DogApplet that implements ActionListener. The applet has buttons labeled: NewDog, FindByBreed, FindByOwner, and showAll. It has text fields for typing dog breed, its name, its weight, and its owner. There is one text area named displayArea to display information about dogs created so far. (d) When the user clicks on the NewDog button, the applet creates a new Dog object with its breed, name, weight, and owner. Assume that the applet can create and save in memory at most 100 dog objects. A user can query the applet. When the user clicks the FindByBreed button, a list of all dogs with the user specified breed is displayed in the displayArea in the sorted order by breed. Similarly, when the user clicks the FindByOwner button, a list of all dogs owned by an owner is displayed in th sorted order by owner. Clicking the showAll button causes the entire database to be displayed in the alphabetical order of breeds. Use frames/panels/menus to make your applet look nice and easy to use! The next two problems are based on the ButtonFun applet discussed on Dec 3 during recitation. Examine the ButtonFun applet. We will make several modifications to this applet and improve the game it implements. 6. Saving and retrieving the score
1 score number_of_clicks 2 score number_of_clicks For example, a sample output for the two players could be: 1 20 59 2 18 75
Source for Problems 6 and 7 (please look at it after attempting the problems yourself) The score save/retrieve feature will work if you compile and run the program on the same computer. 7. Making it a 2-person game
|
||||||||||||||||||||||||||||||||||||||||