Question: Given this code: import java.awt.Image; public class Picture { // attribute that stores an array of Images private Image[] images; // constructor that takes in

Given this code:

import java.awt.Image;

public class Picture {

// attribute that stores an array of Images

private Image[] images;

// constructor that takes in an int parameter for the size of the array

public Picture(int size) {

// initializing the array with the specified size

images = new Image[size];

}

// method to add an image to the array at the specified index

public void addImage(Image image, int index) {

// adding the image to the array at the specified index

images[index] = image;

}

// method to loop through the array and print the hashcode of each non-null image

public void draw() {

// looping through the array

for (int i = 0; i

// checking if the current image is not null

if (images[i] != null) {

// printing the hashcode of the image

System.out.println("Image " + i + ": " + images[i].hashCode());

}}}}

Given this code: import java.awt.Image; public class Picture { // attribute thatstores an array of Images private Image[] images; // constructor that takes

Only Java Code please.

9.2 Witness to the picture Create a class TestFunctionallnterface with a main method. In it, create a Picture object, give it a number of Image objects (check the API, the image can be empty, as long as it is not null.) Call the draw method. 9.3 Blueprints Create a class Blueprint, representing drawings of buildings. A blueprint does nog have Image objects. We will not be bothered by how a blueprint actually looks like. It does have a draw() method however; this one will print a message to the console. Expand the testing class to create a blueprint object and call draw() on it. 9.4 Personal drawings Copy the classes Organism and Climate from the previous chapter to your current project. Create a class Person, having a name, dateOfBirth and an Address (you can sure fill in the rest yourself by now.) Persons are Organisms, so extend the class Organism. Persons can draw themselves. That means they tell something about themselves, by printing a text to the console. Implement all methods a Person class would need, in this case include the method draw(). Expand the testing class to create a person object and call draw() on it. 9.5 A drawer of drawable objects In the testing class, define an array of three Objects (so: Object[] drawings = new Object[3] .) Assign the person object to one slot, the picture to another, the blueprint to the third. Loop through the array and call the draw method on each of them. Hint: you need reflection in order to do this

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!