Question: //Inven 1. Start a new Java project called Inventory2 2. Create a class called MainClass 3. Copy your Inventory class from Lab 9 into the
//Inven
1. Start a new Java project called Inventory2
2. Create a class called MainClass
3. Copy your Inventory class from Lab 9 into the project.
4. Create a class called Requisition that is a subclass of Inventory you will use use the
extends keyword.
(a) Add a private member variable called quantity, representing the number of items ordered
(make sure it doesnt conflict with the Inventory quantity name you chose).
(b) Add a getter and setter method for the quantity.
5. Create a class called Order which will be similar to the Requisition class, but with fields
called quantity (type int) and customerName (type String), along with the appropriate
getters and setters.
6. Modify the Inventory class as follows :
(a) Add a method called resupply which takes an int argument and does the following :
i. Create a new object of type Requisition representing the record of ordering more
of that item
ii. Set all the inherited attributes of the new Requisition object to be the same as the
parent (name, number, price).
iii. Set the quantity attribute of the new Requisition object to be the number passed
into the method.
iv. Add the int parameter to the number of items in stock, representing the store
manager ordering more of the items.
v. Return the new Requisition variable.
(b) Add a method called sell which will be similar to resupply, but will take both an int
and a String, where the String is the name of a customer.
i. Similar to resupply, you will create and return a new Order object, where the
customer name is set from the parameter, as well as the quantity.
ii. The parent Inventory item should subtract the quantity ordered from the stock.
7. Download the InventoryDriver.java file from the course webpage and add it to your program.
8. Try to execute the InventoryDriver class main function. You may need to rename method
calls to match the ones in your class definitions.
tory Class
******************************* Below is a Inventory project to use as maintain in Instruction**************************
public class Inventory {
//private instance variables
private String name;
private int no_items;
private double price;
//Setter for name
public void setName(String name)
{
this.name=name;
}
//Getter for name
public String getName()
{
return name;
}
//Setter for no_items
public void setNo_items(int num)
{
this.no_items=num;
}
//Getter for no_items
public int getNo_items()
{
return no_items;
}
//Setter for price
public void setPrice(double price)
{
this.price=price;
}
//Getter for price
public double getPrice()
{
return price;
}
}
//MainClass class
import java.util.Scanner;
import java.lang.Double;
public class MainClass {
//printInventory function to print details of an item using Getters
public static void printInventory(Inventory item)
{
System.out.println("The name of the item is: "+ item.getName());
System.out.println("The no of items is: "+ item.getNo_items());
System.out.println("The price of the item is: "+ item.getPrice());
}
public static void main(String[] args) {
//scanner to read input
Scanner s = new Scanner(System.in);
//3 objects of Inventory class
Inventory inven1= new Inventory();
Inventory inven2= new Inventory();
Inventory inven3= new Inventory();
//entering details of item-1 using setters
System.out.println("Enter name,no of items in stock & price of item-1");
String name = s.next();
inven1.setName(name);
int no_items = s.nextInt();
inven1.setNo_items(no_items);
double price = s.nextDouble();
inven1.setPrice(price);
printInventory(inven1);
//entering details of item-2 using setters
System.out.println(" Enter name,no of items in stock & price of item-2");
name = s.next();
inven2.setName(name);
no_items = s.nextInt();
inven2.setNo_items(no_items);
price = s.nextDouble();
inven2.setPrice(price);
printInventory(inven2);
//entering details of item-3 using setters
System.out.println(" Enter name,no of items in stock & price of item-3");
name = s.next();
inven3.setName(name);
no_items = s.nextInt();
inven3.setNo_items(no_items);
price = s.nextDouble();
inven3.setPrice(price);
printInventory(inven3);
//modifying price of item-3 using setters
System.out.println(" Now we modify the price of Item-3 from "+price+" to "+(price+10));
inven3.setPrice(price+10);
printInventory(inven3);
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
