Create the following classes (each in a separate .jave file) - Product, Book, Car and ProductTest Product Class has an instance variable: int id and a print() method that displays the String" Product- id: xxx" Product Class has one Constructor for setting value for Id. Book Class inherits from Product. Book Class has 2 String instance variables: Title and Author. The print() method of Book Class displays the String: "Book-Id: xxx, Title:aaaaaaaaaa Author:bbbbbbbbbb". Book Class has one constructor that sets Id, Author and Title. Car Class inherits from Product. Car Class has 2 String instance variables: Make and Model. The print() method of Car Class displays the String: "Car-Id: xxx, Make:mmmmmmm Model:kkkkkkk" Car Class has one constructor that sets ID, Make and Model. ProductTest Class has a main() method that creates the following objects. 1) Book (b1): id:101, Author: John Hill, Title: Java Programming 2) Book(b2): id:102, Author: Jim Sims Title: Python Programming 3) Car(c1): id: 201 Make: Chevy Model: Malibu 4) Car(c2)): id: 202 Make: Ford Model Escape Place the above objects in ArrayList of Products and polymorphically call the print() method of each using an enhanced for() loop. Each object must display the CORRECT DATA from that object POLYMORPHICALLY.
Create the following classes (each in a separate .jave file)
- Product, Book, Car and ProductTest
Product Class has an instance variable: int id and a print() method that displays the String" Product- id: xxx"
Product Class has one Constructor for setting value for Id.
Book Class inherits from Product. Book Class has 2 String instance variables: Title and Author. The print() method of Book Class displays the String: "Book-Id: xxx, Title:aaaaaaaaaa Author:bbbbbbbbbb".
Book Class has one constructor that sets Id, Author and Title.
Car Class inherits from Product. Car Class has 2 String instance variables: Make and Model. The print() method of Car Class displays the String: "Car-Id: xxx, Make:mmmmmmm Model:kkkkkkk"
Car Class has one constructor that sets ID, Make and Model.
ProductTest Class has a main() method that creates the following objects.
1) Book (b1): id:101, Author: John Hill, Title: Java
2) Book(b2): id:102, Author: Jim Sims Title: Python Programming
3) Car(c1): id: 201 Make: Chevy Model: Malibu
4) Car(c2)): id: 202 Make: Ford Model Escape
Place the above objects in ArrayList of Products and polymorphically call the print() method of each using an enhanced for() loop.
Each object must display the CORRECT DATA from that object POLYMORPHICALLY.
DO NOT HARD CODE OUTPUT using System.out.println(). Be sure to use POLYMORPHISM
Upload all 4(four) java files to Canvas.
Trending now
This is a popular solution!
Step by step
Solved in 6 steps with 1 images