Document 15302233

advertisement
CSIT114- Sample Exam 2
Page 1 of 5
CSIT114-Introduction to Computing
Sample Exam 2
Namita Singla
Closed book and notes
April 25, 2006
Question 1: [20 points] Single class design
We would like to create a Painting class. Each painting has a particular
description, the name of the artist who did it and its value.
(a) Write a constructor with description, name of the artist and value initialized.
(b) Write a getArtist() method which returns the name of the artist.
(c) Write a setValue(double value) method which takes new value and sets the
value of painting to the new value.
(d) Write the toString() method.
CSIT114- Sample Exam 2
Page 2 of 5
Question2: [15 points] Collection of objects
The data for all the paintings is stored in a class called ArtMuseum. This class uses an
array to hold Painting objects. The problem is to complete the definition of the methods
in the class ArtMuseum. (
public class ArtMuseum {
private Painting paintings = new Painting[200];
private int paintingCount;
public void addPainting(Painting painting) {
// add new painting to the end of the
// paintings array
}
public void addPainting(String description, String
artist, double value) {
// add new painting with (description, artist and
// value) to the end of the paintings array
}
public boolean findPainting(String artist) {
//
//
//
//
//
Find a painting with artist
"artist" in the array.
If the painting is found in the array,
return true otherwise false should be
returned.
CSIT114- Sample Exam 2
Page 3 of 5
}
}
Question 3: [10 points] Arrays
Implement a method that fills an array intArray with consecutive integer numbers
starting from the length of the array down to 1. For example, if the array is of length 5,
then it should be filled with the values 5, 4, 3, 2, 1.
/**
* Fill the array with integer numbers from N down to 1.
* N is determined by the length of the array.
*/
public void fillArray()
{
CSIT114- Sample Exam 2
}
Question 4 [5 points] this keyword
Explain the use of this keyword.
Question 5 [5 points] Garbage Collection
What is the purpose of garbage collection in Java, and when is it used?
Page 4 of 5
CSIT114- Sample Exam 2
Page 5 of 5
Question 6 [10 points] Method Overloading
(a) Do you see any method overloading in ArtMuseum.java. If yes
then write name of overloaded method.
(b) Overload findPainting method of ArtMuseum.java class such that
the new method takes another Painting object, and find it in
paintings array.
Download