Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Make a new Eclipse Java project .Do not create a package in this project. Let Eclipse create the default package. Create an abstract class called

Make a new Eclipse Java project.Do not create a package in this project. Let Eclipse create the default package.

Create an abstract class called Product. The class should declare the following:

Fields: variables:

  • private instance variable that describes the id - int
  • private instance variable that describes the name - String
  • protected instance variable that describes the price - double
  • private instance variable that describes the production Year- integer

Methods:

  • constructor without argument(.e.g. initialize field to default values) constructor that initializes id, name,price, production Year.
  • Override toString() method that returns the information stored in the above variables.

Make the getter and setter methods for each instance variable except price.

Include an abstract method setPrice(double amount) to determine the price for a product.

Include an abstract method getType()return string (that represent product type the product type

)

Create two subclasses called Software and Book as shown in the figure

Book classshould declare the following Field (private variable):

  • an instance variable that describes the author Name- String Methods:
  • constructor without argument (.e.g. initialize field to default values) - constructor that initializes id, name, price, production Year , author.
  • getter and setter methods for author variable
  • Override setPrice(double amount)method (set price to amount)
  • Override getType to return string product type "Book"
  • Override toString() method that returns the information stored in in the instance variables

Software classshould declare the following

Fields (variable):

  • private instance variable that describes the discount -Boolean Methods:
  • constructor without argument (.e.g. initialize field to default values) - constructor that initializes id, name, price, production Year, discount.
  • getter and setter methods for discount variable
  • Override setPrice(double amount)method should return book price (set price variable as follows if discount variable is true reduce amount by 10% then assign it to price, if discount variable is false set price to amount )
  • Override getType to return string product type "Software"
  • Override toString() method that returns the information stored in the instance variables.

Write a driver program (another class with main method) that uses the above hierarchy. In your driver program do the following.

  • Create array of Products initialize it by calling get products method shown below

Iterate over the array and display product information including price and type for book and software objects.

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_2

Step: 3

blur-text-image_3

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

Using Microsoft Excel and Access 2016 for Accounting

Authors: Glenn Owen

5th edition

1337109048, 1337109045, 1337342149, 9781337342148 , 978-1337109048

More Books

Students also viewed these Programming questions

Question

What do validation rules do?

Answered: 1 week ago