Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Build a new Book class(Book.java). This class will be a sub-class of Product. So it will inherit all the properties of Product(productId, description and price).

Build a new Book class(Book.java). This class will be a sub-class of Product. So it will inherit all the properties of Product(productId, description and price). Also add 4 new properties: title, author, publisher and isbn. A total of 7 properties. Create this class, make sure to add 2 constructors, all set and get methods, a display() method, and a toString method. Then use main to test out this class.

Main Code

Book b1;

b1 = new Book(k77, TextBook, 69.00, Intro to Java, Jones, APress, 9888771212);

b1.display(); //prints all 7 properties

=================================================================================

import java.util.*; import java.lang.*; import java.io.*;

class Product { private String pid; private String description; private double price; Product(String pid,String description,double price){ this.pid=pid; this.description=description; this.price=price; } Product(){ pid="0"; description=""; price=0; } void display(){ System.out.println("PRODUCT ID : "+this.pid); System.out.println("Description : "+this.description); System.out.println("Price : "+this.price); } public static void main (String[] args) throws java.lang.Exception { Product p1; p1=new Product("k77","Blender",69.00); p1.display(); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Fred R. McFadden, Jeffrey Slater, Mary B. Prescott

5th Edition

0805360549, 978-0805360547

More Books

Students also viewed these Databases questions