Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

what is wrong can you rewrite the code to know the enswer

public class Item_in_Stock {

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);

}

public void setItem_price(float item_price) {

this.item_price = item_price;

}

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;

}

}

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;

}

}

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 Item_in_Stock {

String brand;

String type;

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";

}

public String getBrand() {

return brand;

}

public void setBrand(String brand) {

this.brand = brand;

}

public String getType() {

return type;

}

public void setType(String type) {

this.type = type;

}

}

public class Iphone extends Item_in_Stock {

float cost;

float screenSize;

String color;

Iphone(Iphone obj, float cost, float screenSize, String color) {

super(obj);

this.cost = cost;

this.screenSize = screenSize;

this.color = color;

}

// getters and setters

@Override

public String getItemCategory() {

return "Smart Devices";

}

@Override

public String getItemName() {

return "Apple Iphone 12";

}

@Override

public String getItemDescription() {

return "Apple Iphone 12 128GB";

}

public void setCost(float cost) {

this.cost = cost;

}

public void setScreenSize(float screenSize) {

this.screenSize = screenSize;

}

public void setColor(String color) {

this.color = color;

}

}

public class SonyTV extends Item_in_Stock {

String brand;

String type;

SonyTV(SonyTV obj, String type) {

super(obj);

this.brand = "Sony";

this.type = type;

}

@Override

public String getItemCategory() {

return "TV";

}

@Override

public String getItemName() {

return "Sony TV";

}

@Override

public String getItemDescription() {

return "Sony Smart TV 45\"";

}

public String getItemQty() {

return this.itemQty;

}

public String getItemCode() {

return this.itemCode;

}

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Eric Redmond ,Jim Wilson

1st Edition

1934356921, 978-1934356920

More Books

Students also viewed these Databases questions