The data for all the paintings is stored in a class called ArtMuseum. This class
ID: 3633216 • Letter: T
Question
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.
}
}
Explanation / Answer
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
paintings[paintingCount++] = painting;
}
public void addPainting(String description, String artist, double value) {
// add new painting with (description, artist and
// value) to the end of the paintings array
paintings[paintingCount].description = description;
paintings[paintingCount].artist= artist;
paintings[paintingCount].value= value;
}
public boolean findPainting(String artist) {
for(int i=0; i<paintingCount; i++)
{
if(paintings[i].artist.equals(artist))
System.out.println( artist + " found ");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.