In this 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. Task 3.1. Draw a UML class diagram with all the classes and relationships. Task 3.2. 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.   Part 1 code : import java.util.Scanner;   public class ItemInStock { private String itemCode; private String itemName; private String itemDescription; private int quantity; private double itemPrice; private String item_category;   public ItemInStock(String itemCode, int quantity, double itemPrice) { this.itemCode = itemCode; this.quantity = quantity; this.itemPrice = itemPrice;   }   public String getItemCode() { return this.itemCode; }   public void setItemCode(String itemCode) { this.itemCode = itemCode; }   public String getItemName() { return this.itemName; }   public void setItemName(String itemName) { this.itemName = itemName; }   public String getItemDescription() { return this.itemDescription; }   public void setItemDescription(String itemDescription) { this.itemDescription = itemDescription; }   public int getQuantity() { return this.quantity; }   public void setQuantity(int quantity) { this.quantity = quantity; }   public double getItemPrice() { return this.itemPrice; }   public void setItemPrice(double itemPrice) { this.itemPrice = itemPrice; } public String getItem_category() {   return item_category ;   }       public void setItem_category(String item_category) {   this.item_category = item_category;   }     public void addItem() { if (this.quantity + 1 > 25) { System.out.println("The error: Item stock must not exceed 25 items"); } else { this.quantity++; } }   public void itemSell() { Scanner scanner = new Scanner(System.in); System.out.print("Enter the quantity of items to sell: "); int sellQuantity = scanner.nextInt(); if (sellQuantity > this.quantity) { System.out.println("Error: Not enough items in stock"); } else { this.quantity -= sellQuantity; } }   public double taxOnItem() { return this.itemPrice * 0.05; }   public double getItemPriceWithTax() { return this.itemPrice + this.taxOnItem(); }   public void getItemDetails() { System.out.println("Item Category: " + this.getItem_category()); System.out.println("Item Name: " + this.getItemName()); System.out.println("Description: " + this.getItemDescription()); System.out.println("StockCode: " + this.getItemCode()); System.out.println("Price Without Tax: R. O " + this.getItemPrice()); System.out.println("Price With Tax: R.O " + this.getItemPriceWithTax()); System.out.println("Total quantity in store: " + this.getQuantity()); } }   Part 2 code public class HP_Laptop extends ItemInStock { private String processor; private int memory; private int storage;   public HP_Laptop(String itemCode, int quantity, double itemPrice, String processor, int memory, int storage) { super(itemCode, quantity, itemPrice); this.processor = processor; this.memory = memory; this.storage = storage; }   @Override public String getItem_category() { return "Laptop"; }   @Override public String getItemName() { return "HP Laptop"; }   @Override public String getItemDescription() { return "HP " + processor + " " + memory + "GB " + storage + "GB"; }   @Override public void getItemDetails() { super.getItemDetails(); System.out.println("Processor: " + processor); System.out.println("Memory: " + memory + "GB"); System.out.println("Storage: " + storage + "GB"); } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Answer this qustion with refer to the part 1 and part 2 codes only an eample how to write in pic:

In this 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.

Task 3.1. Draw a UML class diagram with all the classes and relationships.

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

 

Part 1 code :

import java.util.Scanner;

 

public class ItemInStock {

private String itemCode;

private String itemName;

private String itemDescription;

private int quantity;

private double itemPrice;

private String item_category;

 

public ItemInStock(String itemCode, int quantity, double itemPrice) {

this.itemCode = itemCode;

this.quantity = quantity;

this.itemPrice = itemPrice;

 

}

 

public String getItemCode() {

return this.itemCode;

}

 

public void setItemCode(String itemCode) {

this.itemCode = itemCode;

}

 

public String getItemName() {

return this.itemName;

}

 

public void setItemName(String itemName) {

this.itemName = itemName;

}

 

public String getItemDescription() {

return this.itemDescription;

}

 

public void setItemDescription(String itemDescription) {

this.itemDescription = itemDescription;

}

 

public int getQuantity() {

return this.quantity;

}

 

public void setQuantity(int quantity) {

this.quantity = quantity;

}

 

public double getItemPrice() {

return this.itemPrice;

}

 

public void setItemPrice(double itemPrice) {

this.itemPrice = itemPrice;

}

public String getItem_category() {

 

return item_category ;

 

}

 

 

 

public void setItem_category(String item_category) {

 

this.item_category = item_category;

 

}

 

 

public void addItem() {

if (this.quantity + 1 > 25) {

System.out.println("The error: Item stock must not exceed 25 items");

} else {

this.quantity++;

}

}

 

public void itemSell() {

Scanner scanner = new Scanner(System.in);

System.out.print("Enter the quantity of items to sell: ");

int sellQuantity = scanner.nextInt();

if (sellQuantity > this.quantity) {

System.out.println("Error: Not enough items in stock");

} else {

this.quantity -= sellQuantity;

}

}

 

public double taxOnItem() {

return this.itemPrice * 0.05;

}

 

public double getItemPriceWithTax() {

return this.itemPrice + this.taxOnItem();

}

 

public void getItemDetails() {

System.out.println("Item Category: " + this.getItem_category());

System.out.println("Item Name: " + this.getItemName());

System.out.println("Description: " + this.getItemDescription());

System.out.println("StockCode: " + this.getItemCode());

System.out.println("Price Without Tax: R. O " + this.getItemPrice());

System.out.println("Price With Tax: R.O " + this.getItemPriceWithTax());

System.out.println("Total quantity in store: " + this.getQuantity());

}

}

 

Part 2 code

public class HP_Laptop extends ItemInStock {

private String processor;

private int memory;

private int storage;

 

public HP_Laptop(String itemCode, int quantity, double itemPrice, String processor, int memory, int storage) {

super(itemCode, quantity, itemPrice);

this.processor = processor;

this.memory = memory;

this.storage = storage;

}

 

@Override

public String getItem_category() {

return "Laptop";

}

 

@Override

public String getItemName() {

return "HP Laptop";

}

 

@Override

public String getItemDescription() {

return "HP " + processor + " " + memory + "GB " + storage + "GB";

}

 

@Override

public void getItemDetails() {

super.getItemDetails();

System.out.println("Processor: " + processor);

System.out.println("Memory: " + memory + "GB");

System.out.println("Storage: " + storage + "GB");

}

}

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];
Transcribed Image Text: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];
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education