






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
Material Type: Exam; Class: OBJECT-ORIENTED PROG I; Subject: Computer Science; University: University of Maryland; Term: Spring 2005;
Typology: Exams
1 / 10
This page cannot be seen from the preview
Don't miss anything!







First Name: _______________________
Last Name: _______________________
Student ID: _______________________
Section time (Circle One): 8AM 9AM 10AM 11AM 12PM 1PM
I pledge on my honor that I have not given or received any unauthorized assistance on this examination.
Your signature: _____________________________________________________________
General Rules (Read):
Grader Use Only:
#1 (40) #2 (15) #3 (30) #4 (15)
Total (100)
Problem 1 General Questions (40 pts)
a. (3 pts) Which of the following Java constructs can be used to control the program execution in an iteration statement? Circle your choice(s).
i. break
ii. continue
iii. static
b. (3 pts) Math.random() generates a double value greater than or equal to 0 and less than 1. Define an expression that generates a random value greater than or equal to 10 and less than
c. (4 pts) Answer the questions below based on the following prototypes:
int raise(float x); // prototype 1
int raise(String x); // prototype 2
float raise(float x); // prototype 3
int lower(float x); // prototype 4
i. Do the methods represented by prototypes 1 and 2 overload each other? Yes/No ii. Do the methods represented by prototypes 1 and 3 overload each other? Yes/No iii. Do the methods represented by prototypes 2 and 3 overload each other? Yes/No iv. Do the methods represented by prototypes 1 and 4 overload each other? Yes/No
d. (2 pts) Can you declare a formal parameter with the same name as a local variable? Yes/No
e. (2 pts) Can constructors be overloaded? Yes/No.
k. (8 pts) Rewrite the following cascaded if statement into a switch statement (t and x are integer variables).
if (t = = 3) x = 30; else if (t == 4) x = 10; else if (t == 2 || t = = 7 || t = = 8) x = 20; else x = 100;
Write the switch statement here.
l. (5 pts) Based on the following two declarations indicate whether the expressions below are valid or invalid?
String b = "Hello"; char[] c = {'H', 'e', 'l', 'l', 'o'};
System.out.println(b[2]); // VALID / INVALID
System.out.println(b.length); // VALID / INVALID
System.out.println(c.length()); // VALID / INVALID
System.out.println(c.charAt(1)); // VALID / INVALID
System.out.println(String.valueOf(c)); // VALID / INVALID
Problem 3 Class Implementation (30 pts)
A catering program uses a class named “Party” to keep track of information about a party. The class has the following two private instance variables:
private String name; // Represents the name of the party private double cost; // Represents the cost of the party in dollars
Define the following Party class methods (you don’t to have to define the class). All the methods are non- static unless otherwise specified.