Question
Please provide the whole CODE of my qustion base on the Below codes Part 1 code : import java.util.Scanner; public class ItemInStock { private String
Please provide the whole CODE of my qustion base on the Below codes
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");
}
}
HeRe is the qustion
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
In pic it is an example of how it can be the started
PLS PLS PLS write the code base on part 1 and 2 code
Example. class polymorphism_works \{ public static void specific_Item(Item_in_Stock OBJ)\{ System.out.println("Item in stock details"); System.out.println(OBJ); 3 public static void main(String] args) \{ Item_in_Stock [] Item_list = new Item_in_Stock [3]Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started