Make a new Eclipse Java project .Do not create a package in this project. Let Eclipse create
Question:
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.
Using Microsoft Excel and Access 2016 for Accounting
ISBN: 978-1337109048
5th edition
Authors: Glenn Owen