Question: Please help! Thank you!! Declare at least 2 instance variables for each of the classes below. Create an inheritance or association relationship for some of

Please help! Thank you!!

Declare at least 2 instance variables for each of the classes below. Create an inheritance or association relationship for some of them.

class ItemForSale {

}

class Movie {

}

class Book {

}

class Author {

}

public class Store { // instance variable (could be an array or ArrayList of one of the classes above)

public static void main(String[] args) { Store s = new Store(); Book b = new Book(); System.out.println(b instanceof ItemForSale); } }

*AND THIS ONE*

Create a Square class that inherits from Rectangle.

class Rectangle { private int length; private int width;

public Rectangle() { length = 1; width = 1; }

public Rectangle(int l, int w) { length = l; width = w; }

public void draw() { for(int i=0; i < length; i++) { for(int j=0; j < width; j++) System.out.print("* "); System.out.println(); } System.out.println(); }

}

// 1. Make the class square inherit from Rectangle public class Square { // 2. Add a Square no-argument constructor

// 3. Add a Square constructor with 1 argument for a side

public static void main(String[] args) { Rectangle r = new Rectangle(3,5); r.draw(); // 4. Uncomment these to test // Square s1 = new Square(); // s1.draw(); // Square s = new Square(3); // s.draw(); } }

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!