Question
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
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.
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.
and this is my part 1 code
/**
* @author YourName
*
*/
public class Item_in_Stock {
private String item_code;
private String item_name;
private String item_description;
private String item_category;
private int item_quantity;
private float item_price;
// setting tax rate 5%
private final float TAX_RATE = 5;
/**
* Parameterized Constructor
*
* @param item_code
* @param item_quantity
* @param item_price
*/
public Item_in_Stock(String item_code, int item_quantity, float item_price) {
super();
this.item_code = item_code;
this.item_quantity = item_quantity;
this.item_price = item_price;
// initializing other variables
this.item_name = "Unknown Item Name";
this.item_description = "Unknown Item Description";
this.item_category = "Unknown Item Category";
}
// Getters and setters
/**
* @return the item_code
*/
public String getItem_code() {
return item_code;
}
/**
* @param item_code the item_code to set
*/
public void setItem_code(String item_code) {
this.item_code = item_code;
}
/**
* @return the item_name
*/
public String getItem_name() {
return item_name;
}
/**
* @param item_name the item_name to set
*/
public void setItem_name(String item_name) {
this.item_name = item_name;
}
/**
* @return the item_description
*/
public String getItem_description() {
return item_description;
}
/**
* @param item_description the item_description to set
*/
public void setItem_description(String item_description) {
this.item_description = item_description;
}
/**
* @return the item_category
*/
public String getItem_category() {
return item_category;
}
/**
* @param item_category the item_category to set
*/
public void setItem_category(String item_category) {
this.item_category = item_category;
}
/**
* @return the item_quantity
*/
public int getItem_quantity() {
return item_quantity;
}
/**
* @param item_quantity the item_quantity to set
*/
public void setItem_quantity(int item_quantity) {
this.item_quantity = item_quantity;
}
/**
* @return the item_price without tax
*/
public float getItem_price_without_tax() {
return item_price;
}
/**
* @return the item price with tax
*/
public float getItem_price_with_tax() {
return item_price + (((float) item_price / 100) * TAX_RATE);
}
/**
* @param item_price the item_price to set without tax
*/
public void setItem_price(float item_price) {
this.item_price = item_price;
}
/**
* This method add items in stock with a check that item stock does not exceed
* 25.
*
* @param newStock
*/
public void add_Item(int newStock) {
if (item_quantity + newStock > 25) {
System.out.println("Item cannot be added as available stock size exceeds 25!");
} else {
item_quantity += newStock;
}
}
/**
* This method sell items, it reduces the stock accordingly
*
* @param quantityToSell
*/
public void item_Sell(int quantityToSell) {
if (item_quantity - quantityToSell < 0) {
System.out.println(quantityToSell + " many Item is not in stock!");
} else {
item_quantity -= quantityToSell;
}
}
/**
* @return the tax_rate on item
*/
public float tax_on_Item() {
return TAX_RATE;
}
/**
* @return item details
*/
public String get_Item_Details() {
return "Item_in_Stock [item_code=" + item_code + ", item_name=" + item_name + ", item_description="
+ item_description + ", item_category=" + item_category + ", item_quantity=" + item_quantity
+ ", item_price without tax=" + item_price + ", item_price with tax=" + getItem_price_with_tax() + "]";
}
}
also this is for part 2
/**
* @author YourName
*
*/
public class Stocked_Item {
/**
* @param args
*/
public static void main(String[] args) {
/*
* Test Case 1#
* create object of Item_in_Stock class
*/
Item_in_Stock item = new Item_in_Stock("C10", 45, 12.5f);
/*
* Test case 2#
* It will test whether program is returning unknown values as unknown
* or not
*/
System.out.println("Category : " + item.getItem_category());
System.out.println("Name : " + item.getItem_name());
System.out.println("Description: " + item.getItem_description());
/**
* Test Case 3#
* Trying to sell items more than available stock
*
* It would print error message
*/
item.item_Sell(50);
/**
* Test Case 4#
* Trying to add items not more than 25
*
* It would print error message
*/
item.add_Item(100);
/**
* Test Case 5#
* Trying to get item price with tax and without tax
*
* without tax it should be 12.5
* with tax it should be 13.125
*/
System.out.println("Price of item without tax: " + item.getItem_price_without_tax());
System.out.println("Price of item with tax: " + item.getItem_price_with_tax());
/**
* Test case 6#
* Adding other information of item and after that try to fetch the details
*
* All available details should be printed
*/
item.setItem_name("Book");
item.setItem_category("Stationary");
item.setItem_description("Reference books");
// getting the details
System.out.println(" " + item.get_Item_Details());
}
}
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