Task 3 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.   More info:  In this last and final 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.   (please see the photos if you need)

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Task 3 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.

 


More info: 

In this last and final 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.

 

(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 ()
Transcribed Image Text: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 ()
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()
Transcribed Image Text: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()
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY