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.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter10: Introduction To Inheritance
Section: Chapter Questions
Problem 1GZ
icon
Related questions
Question

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.

DO NOT HARD CODE OUTPUT using System.out.println(). Be sure to use POLYMORPHISM

Upload all 4(four) java files to Canvas.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 6 steps with 1 images

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT