Question: what is wrong with this code it does not work for me can you solve it public class Item_in_Stock { String item_code; String item_name; String
what is wrong with this code it does not work for me can you solve it
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
Get step-by-step solutions from verified subject matter experts
