
Task 3 question: 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.
More info:
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.
(please see the photos if you need)
![Complete Code:
//create a class
class Item_in_Stock
{
//Declare variable to store code of the item
String Item_code;
//Declare variable to store item description
String Item_desc;
//Declare variable to store stock of quantity
int qty_stock;
//Declare variable to store price of quantity
double item_price;
//Create a constructor
Item_in_Stock(String itemcode, int qtystock, int itemprice)
{
//initialize the itemcode
this.Item_code = itemcode;
//initialize the quantity
this.qty_stock = qtystock;
//initialize the price
this.item_price = itemprice;
}
//Declare get method for Item_code
String getItem_code()
{
//return item_code
return (this.Item_code);
}
//Declare set method for Item_code
void setItem_code(String itemcode)
{
//set the itemcode
this.Item_code = itemcode;
}
//Declare get method for Item_desc
String getItem_desc()
{
//return Item_desc
return (this.Item_desc);
}
//Declare set method for ITem_desc
void setItem_desc(String itemdesc)
{
//Initialize Item_code
this.Item_code = itemdesc;
}
//Declare get method for qty_stock
int getqty_stock(int stock)
{
//return the quantity stock
return (this.qty_stock);
}
//Declare qty_stock method
void setqty_stock(String itemdesc)
{
//initialize the variable qty_stock
this.qty_stock = qty_stock;
}
//Declare getitemprice
double getitem_price()
{
//return the item_price
return(this.item_price);
}
//Declare method to set item_price
void setitem_price(int price)
{
//initilailze item_price
this.item_price=price;
}
//Declare method getItemcat
String getItemCat()
{
//return the message
return(" Unknown Item Category");
}
//Declare method getItem Name
String getItemName()
{
//return the message
return(" Unknown Item Name");
}
//Declare the method get| Tem Description
String getItem Description()
{
//return the message
return(" Unknown Item Description");
}
//Declare the method add_item
void add_item(int item)
{
//check if the stock exceeds
if (this.qty_stock + item >25)
//Display the message
System.out.println("The error:Item stock must not exceed 25 items"
else
{
}
}
//if the stock does not exceed revise the stock
this.qty_stock = this.qty_stock+ item;
//Declare the method item_sell
void item_sell(int item)
{
//check if the stock is available
if (this.qty_stock <=0)
//Display the message
System.out.println("No stock is available");
else
{
}
//Update the stock
this.qty_stock = this.qty_stock-item;
}
//Declare the method tax_on_item to find the tax on an item
void tax_on_Item()
{
//Declare a variable tax to store the tax
double tax = this.qtv stock * 0.05:
//Display the message
System.out.println("The tax is " + tax);
}
//Declare method to set price of item without tax
void setitempricenotax(int price)
{
//Initialize the price without tax
this.item_price=price;
}
//Declare method to getitem
double getitempricenotax()
{
//return the item_price
return (this.item_price);
}
//Declare method getitemprice with tax
double getitempricetax()
{
//update the price with the tax
double price = this.item_price + this.item_price* 0.05;
//return the tax
return(price);
}
//Declare the method get_Item_Details
void get_Item_Details()
{
//Display the message
System.out.println("Laptops item stock information:");
System.out.println("Item Category:"+ this.getItemCat());
System.out.println("Item Name:" + this.getItemName());
System.out.println("Description:" + this.getItem Description());
System.out.println("Stockcode" + this.Item_code);
}
};
//Declare the class
class stock
{
public static void main(String args[])
{
//Declare object
Item_in_Stock 01 = new Item_in_Stock("C15",5,180);
//Display the details
01.get_Item_Details();
//add 3 items to the stock
01.add_item(3);
Price Without tax: R.0 180.0
Price with tax: R.0189.0
Total quantity in store : 8
Laptops item stock information:
Item Category: Unknown Item Category
Item Name: Unknown Item Name 2
System.out.println("Price with tax : R.O" + this.getitempricetax()); Description: Unknown Item Description
System.out.println("Price Without tax : R.O " + this.item_price);
System.out.println("Total quantity in store " + this.qty_stock);
Stockcode : C15
Price Without tax: R.0 180.0
Price with tax: R.0189.0
Total quantity in store : 6
Laptops item stock information:
Item Category: Unknown Item Category
Item Name: Unknown Item Name2
//display the details
01.get_Item_Details();
//add 2 items to the stock
01.item_sell(2);
Part one answers: code,output,and diagram
//Display the details
01.get_Item_Details();
//Update the price of items to 200
01.setitem_price(200);
01.get_Item_Details();
//add the stock
01.add_item(25);
Output:
Laptops item stock information:
Item Category: Unknown Item Category
Item Name: Unknown Item Name2
Description: Unknown Item Description
Stockcode : C15
Price Without tax: R.0 180.0
Price with tax: R.0189.0
Total quantity in store : 5
Laptops item stock information:
Item Category: Unknown Item Category
Item Name: Unknown Item Name2
Description: Unknown Item Description
Stockcode: C15
Description: Unknown Item Description
Stockcode: C15
Price Without tax: R.0 200.0
Price with tax: R.0210.0
Total quantity in store : 6
The error:Item stock must not exceed 25 item
Press any key to continue.
Item-im-Stock
- item_code: String
item-name: String
item-Description : string
-quantity-in-stock: 'mt
- item - price : double
-
+ item_m_Stock (String, int, double)
+ getItem Code (); String
+ getItem Name(); string
+ getItem Description (); String
+ get Quantity In Stock(): int
+ getItem Cat (): string
+ add-Item ()
+ item_sell()
+ tax_om__item(): double
+ setItem price ()
+ get itemprice Without Tax():
double
+getItemprice with Tax():couble
+getItem-Details ()](https://content.bartleby.com/qna-images/question/4e5f358a-93dd-4ca8-9db7-e8099ebb1ddc/57ab7b0d-4bca-40d4-9c37-ba4e81c637fa/6teqzsx_thumbnail.jpeg)


Step by stepSolved in 3 steps

- PART ONE In C# create a Contestant class with the following characteristics: The Contestant class contains public static arrays that hold talent codes and descriptions. Recall that the talent categories are Singing, Dancing, Musical instrument, and Other. Name these fields talentCodes and talentStrings respectively. The class contains an auto-implemented property Name that holds a contestant’s name. The class contains fields for a talent code (talentCode) and description (talent). The set accessor for the code assigns a code only if it is valid. Otherwise, it assigns I for Invalid. The talent description is a read-only property that is assigned a value when the code is set. Modify the GreenvilleRevenue.cs program (See Program Below) so that it uses the Contestant class and performs the following tasks: The program prompts the user for the number of contestants in this year’s competition; the number must be between 0 and 30. The program continues to prompt the user until a valid value…arrow_forwardInheritance, Polymorphism, ArrayLists, Throwing Exceptions The UML diagram below shows a set of classes designed to represent a music collection from 1995. The constructors and methods all function in the standard way, except: The equipmentRequired method should return “Record Player” or “CD Player” as appropriate.The getAlbum method of the NinetiesMusicCollection class accepts an index and returns the corresponding Album object. This method throws an IllegalArgumentException if the index is out of range. (This is the only exception you have to throw anywhere in your code.)In the NinetiesMusicCollection constructor, you can assume the ArrayList<Album> object passed as an argument is not null . Don’t worry about privacy leaks.Implement this set of classes in Java. Note the italics on the Class name “Album” and the method name “equipmentRequired” in the Album class.arrow_forwardImplement a nested class composition relationship between any two class types from the following list: Advisor Вook Classroom Department Friend Grade School Student Teacher Tutor Write all necessary code for both classes to demonstrate a nested composition relationship including the following: a. one encapsulated data member for each class b. inline default constructor using constructor delegation for each class c. inline one-parameter constructor for each class d. inline accessors for all data members e. inline mutators for all data membersarrow_forward
- Javaarrow_forwardin c++ Define another new class named “Item” that must inherit from the given Name class. This Item class will manage the following info: name (string) and price (double). It must prevent the creation of an Item object with either an empty or all-blank name. This class must at least complete the methods defined in the Name class: toString method returns a string representation of the Item object in the format of “ITEM( <name> ) PRICE($ <price> ) such as ITEM(eraser) PRICE($1.05) contains method that accepts a search string and returns true if only the name of the item contains the search string as a substring. It returns false otherwise. isTheSame method that compares two Item objects and returns true only if both Item objects have the exact same name (regardless of the price) and false otherwise. Please note that if the given object in the parameter is not an Item object, it will return false.arrow_forwardInstructions-Java Assignment is to define a class named Address. The Address class will have three private instance variables: an int named street_number a String named street_name and a String named state. Write three constructors for the Address class: an empty constructor (no input parameters) that initializes the three instance variables with default values of your choice, a constructor that takes the street values as input but defaults the state to "Arizona", and a constructor that takes all three pieces of information as input Next create a driver class named Main.java. Put public static void main here and test out your class by creating three instances of Address, one using each of the constructors. You can choose the particular address values that are used. I recommend you make them up and do not use actual addresses. Run your code to make sure it works. Next add the following public methods to the Address class and test them from main as you go: Write getters and…arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





