In this part of the course work you are required to change the definition of the Item_in_Stock class to make it an abstract class and change the getItemCat(), getItemName() and getItemDescription() definitions to make them abstract methods. You are then required to design and implement three classes which are derived from Item_in_Stock class to fully demonstrate the concept of inheritance and polymorphism. Implementation of HP_Laptop class in part II should have given you an idea of inheritance and polymorphism. Three sub classes, one class against each category (Computers, Laptops and Accessories), should contain appropriate constructors, instance variables, setter and getters methods and overridden methods for getItemName(), getItemDescription() and get_Item_details() method. You should be creative and come up with your own ideas of sub-classes. The question: Write code in Java with all these classes implementation and a program called Polymorphism_works with member method specific_Item which takes one instance of Item_in_Stock class as a parameter. Perform functionality of adding items, selling items and changing item price and displaying items details against specific item instance. There should be a main () method which declares an array of objects containing instance of sub classes of Item_in_Stock class and then calls methods of each of the implemented classes.
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
In this part of the course work you are required to change the definition of the Item_in_Stock class to make it an abstract class and change the getItemCat(), getItemName() and getItemDescription() definitions to make them abstract methods.
You are then required to design and implement three classes which are derived from Item_in_Stock class to fully demonstrate the concept of inheritance and polymorphism. Implementation of HP_Laptop class in part II should have given you an idea of inheritance and polymorphism.
Three sub classes, one class against each category (Computers, Laptops and Accessories), should contain appropriate constructors, instance variables, setter and getters methods and overridden methods for getItemName(), getItemDescription() and get_Item_details() method.
You should be creative and come up with your own ideas of sub-classes.
The question: Write code in Java with all these classes implementation and a program called Polymorphism_works with member method specific_Item which takes one instance of Item_in_Stock class as a parameter. Perform functionality of adding items, selling items and changing item price and displaying items details against specific item instance. There should be a main () method which declares an array of objects containing instance of sub classes of Item_in_Stock class and then calls methods of each of the implemented classes.
Example.
.
.
.
class polymorphism_works {
public static void specific_Item(Item_in_Stock OBJ){
.
.
.
System.out.println("Item in stock details");
System.out.println(OBJ);
.
.
.
}
public static void main(String[] args) {
Item_in_Stock [] Item_list = new Item_in_Stock [3];
.
.
.
}
}
(please see the photos if you need)
![Complete Code:
//create a class
class Item_in_Stock
{
//Declare variable to store code of the item
String Item_code;
//Declare variable to store item description
String Item_desc;
//Declare variable to store stock of quantity
int qty_stock;
//Declare variable to store price of quantity
double item_price;
//Create a constructor
Item_in_Stock(String itemcode, int qtystock, int itemprice)
{
//initialize the itemcode
this.Item_code = itemcode;
//initialize the quantity
this.qty_stock = qtystock;
//initialize the price
this.item_price = itemprice;
}
//Declare get method for Item_code
String getItem_code()
{
//return item_code
return (this.Item_code);
}
//Declare set method for Item_code
void setItem_code(String itemcode)
{
//set the itemcode
this.Item_code = itemcode;
}
//Declare get method for Item_desc
String getItem_desc()
{
//return Item_desc
return (this.Item_desc);
}
//Declare set method for ITem_desc
void setItem_desc(String itemdesc)
{
//Initialize Item_code
this.Item_code = itemdesc;
}
//Declare get method for qty_stock
int getqty_stock(int stock)
{
//return the quantity stock
return (this.qty_stock);
}
//Declare qty_stock method
void setqty_stock(String itemdesc)
{
//initialize the variable qty_stock
this.qty_stock = qty_stock;
}
//Declare getitemprice
double getitem_price()
{
//return the item_price
return(this.item_price);
}
//Declare method to set item_price
void setitem_price(int price)
{
//initilailze item_price
this.item_price=price;
}
//Declare method getItemcat
String getItemCat()
{
//return the message
return(" Unknown Item Category");
}
//Declare method getItem Name
String getItemName()
{
//return the message
return(" Unknown Item Name");
}
//Declare the method get| Tem Description
String getItem Description()
{
//return the message
return(" Unknown Item Description");
}
//Declare the method add_item
void add_item(int item)
{
//check if the stock exceeds
if (this.qty_stock + item >25)
//Display the message
System.out.println("The error:Item stock must not exceed 25 items"
else
{
}
}
//if the stock does not exceed revise the stock
this.qty_stock = this.qty_stock+ item;
//Declare the method item_sell
void item_sell(int item)
{
//check if the stock is available
if (this.qty_stock <=0)
//Display the message
System.out.println("No stock is available");
else
{
}
//Update the stock
this.qty_stock = this.qty_stock-item;
}
//Declare the method tax_on_item to find the tax on an item
void tax_on_Item()
{
//Declare a variable tax to store the tax
double tax = this.qtv stock * 0.05:
//Display the message
System.out.println("The tax is " + tax);
}
//Declare method to set price of item without tax
void setitempricenotax(int price)
{
//Initialize the price without tax
this.item_price=price;
}
//Declare method to getitem
double getitempricenotax()
{
//return the item_price
return (this.item_price);
}
//Declare method getitemprice with tax
double getitempricetax()
{
//update the price with the tax
double price = this.item_price + this.item_price* 0.05;
//return the tax
return(price);
}
//Declare the method get_Item_Details
void get_Item_Details()
{
//Display the message
System.out.println("Laptops item stock information:");
System.out.println("Item Category:"+ this.getItemCat());
System.out.println("Item Name:" + this.getItemName());
System.out.println("Description:" + this.getItem Description());
System.out.println("Stockcode" + this.Item_code);
}
};
//Declare the class
class stock
{
public static void main(String args[])
{
//Declare object
Item_in_Stock 01 = new Item_in_Stock("C15",5,180);
//Display the details
01.get_Item_Details();
//add 3 items to the stock
01.add_item(3);
Price Without tax: R.0 180.0
Price with tax: R.0189.0
Total quantity in store : 8
Laptops item stock information:
Item Category: Unknown Item Category
Item Name: Unknown Item Name 2
System.out.println("Price with tax : R.O" + this.getitempricetax()); Description: Unknown Item Description
System.out.println("Price Without tax : R.O " + this.item_price);
System.out.println("Total quantity in store " + this.qty_stock);
Stockcode : C15
Price Without tax: R.0 180.0
Price with tax: R.0189.0
Total quantity in store : 6
Laptops item stock information:
Item Category: Unknown Item Category
Item Name: Unknown Item Name2
//display the details
01.get_Item_Details();
//add 2 items to the stock
01.item_sell(2);
Part one answers: code,output,and diagram
//Display the details
01.get_Item_Details();
//Update the price of items to 200
01.setitem_price(200);
01.get_Item_Details();
//add the stock
01.add_item(25);
Output:
Laptops item stock information:
Item Category: Unknown Item Category
Item Name: Unknown Item Name2
Description: Unknown Item Description
Stockcode : C15
Price Without tax: R.0 180.0
Price with tax: R.0189.0
Total quantity in store : 5
Laptops item stock information:
Item Category: Unknown Item Category
Item Name: Unknown Item Name2
Description: Unknown Item Description
Stockcode: C15
Description: Unknown Item Description
Stockcode: C15
Price Without tax: R.0 200.0
Price with tax: R.0210.0
Total quantity in store : 6
The error:Item stock must not exceed 25 item
Press any key to continue.
Item-im-Stock
- item_code: String
item-name: String
item-Description : string
-quantity-in-stock: 'mt
- item - price : double
-
+ item_m_Stock (String, int, double)
+ getItem Code (); String
+ getItem Name(); string
+ getItem Description (); String
+ get Quantity In Stock(): int
+ getItem Cat (): string
+ add-Item ()
+ item_sell()
+ tax_om__item(): double
+ setItem price ()
+ get itemprice Without Tax():
double
+getItemprice with Tax():couble
+getItem-Details ()](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F4e5f358a-93dd-4ca8-9db7-e8099ebb1ddc%2Fcd0d4d47-8d14-4ef9-9612-c5e849c62fe9%2Frtt1wy_processed.jpeg&w=3840&q=75)
![Part two answers code, and diagram
HPLaptop.java
public class HPLaptop extends ItemInStock {
String brand;
String type;
// to use this constructor you have to create a constructor in ItemInStock also
// by passing ItemInStock obj in parameter
HPLaptop (HPLaptop obj, String type) {
super(obj);
this.brand = "HP";
this.type = type;
}
@Override
public String getItemCategory() {
return "LAPTOP";
}
}
@Override
public String getItemName() {
return "HP_Laptop";
@Override
public String getItem Description() {
return " HP_15_11G_8GB_ITB"";
}
// to create item details class I need the code you prepared for part 1.
}
itemStock
-itemCode: String
-itemName: String
-item Description
-itemQty:int
-itemCategory: String
+getItemQty(): int
+setItemName():void
HPLaptop
-brand:string
-type:string
+setBrand()
+getType()](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F4e5f358a-93dd-4ca8-9db7-e8099ebb1ddc%2Fcd0d4d47-8d14-4ef9-9612-c5e849c62fe9%2Fze8tv9a_processed.jpeg&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 3 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)