Question
In this part of the course work, you are required to design and implement a class called HP_Laptop with instance variables specific to this type
In this part of the course work, you are required to design and implement a class called HP_Laptop with instance variables specific to this type of items, a constructor with parameters which initialises class data members and invokes the Item_in_Stock constructor when it is invoked using inheritance concept in java and initialises data members of Item_in_stock class as well. This class should be designed and implemented in a way that it overrides getItemCategory() that returns the category of the item, getItemName() that returns HP_Laptop and getItemDescription() that returns HP_I5_11G_8GB_1TB . The Class should also override the get_item_details() method to display the complete details of an item.
Task 2.1. Re-draw UML class diagram which was drawn in part 1 of the course work with this new class HP_Laptop. Relationships should also be represented.
Task 2.2. Implement a class called Item_check with a main method to test HP_Laptop class by defining object of the class and invoking methods.
I wrote this code to solve the above question but it give me an error
public class Item_in_Stock {
String item_code;
String item_name;
String item_description;
String item_category;
int item_quantity;
float item_price;
String itemCode;
String itemName;
String itemDescription;
String itemQty;
String itemCat;
// setting tax rate 5%
private final float TAX_RATE = 5;
ItemInStock(Item_In_Stock obj)
{
this.itemCode = obj.itemCode;
this.itemName = obj.itemName;
this.itemQty = obj.itemQty;
this.itemDescription = obj.itemDescription;
this.itemCat = obj.itemCat;
}
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
* 120.
*
* @param newStock
*/
public void add_Item(int newStock) {
if (item_quantity + newStock > 120) {
System.out.println("Item cannot be added as available stock size exceeds 120!");
} 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() + "]";
}}
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 getItemDescription()
{
return " HP_15_11G_8GB_ITB"";
}
}}
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