Question

In: Computer Science

a) Design a Java Class which represents a Retail Item. It is to have the following fields

 a) Design a Java Class which represents a Retail Item. It is to have the following fields

 Item Name

 Item Serial No

 Item Unit Price

 Item Stock Level

 Item Reorder Level

 It is to have at least the following methods an Observer, Mutator and a Display method for each field. It is also to have a buy and a restock method and a method to issue a warning if the stock level goes below the re-order level.

 b) Extend the Retail Item class of part a) above to represent a Perishable Item.

 This subclass will have extra fields to represent expiry date, storage instructions and a consume deadline i,e the number of days in which the item must be consumed once opened.

 Again have at least the following methods for these new fields, namely an Observer, Mutator and a Display method. Also have a method

 which displays the number of days until the expiry date.

 c) Write a control program which creates five instances of standard retail items and five instances of perishable items.

 1. Buy 2 Retail Items and 3 perishable items

 2. Display the Stock levels of any two items

 3. Calculate the total value of Items in Stock including perishable items Note Do not include any perishable items which are past their sell-by date

 4. Re-order Stock for any three Items


Solutions

Expert Solution


public class RetailItem {

   private String itemName;
   private String serialNumber;
   private int unitPrice;
   private int stockLevel;
   private int reorderLevel;
   public RetailItem(String itemName, String serialNumber, int unitPrice, int stockLevel, int reorderLevel) {
       this.itemName = itemName;
       this.serialNumber = serialNumber;
       this.unitPrice = unitPrice;
       this.stockLevel = stockLevel;
       this.reorderLevel = reorderLevel;
   }
   public String getItemName() {
       return itemName;
   }
   public void setItemName(String itemName) {
       this.itemName = itemName;
   }
   public String getSerialNumber() {
       return serialNumber;
   }
   public void setSerialNumber(String serialNumber) {
       this.serialNumber = serialNumber;
   }
   public int getUnitPrice() {
       return unitPrice;
   }
   public void setUnitPrice(int unitPrice) {
       this.unitPrice = unitPrice;
   }
   public int getStockLevel() {
       return stockLevel;
   }
   public void setStockLevel(int stockLevel) {
       this.stockLevel = stockLevel;
   }
   public int getReorderLevel() {
       return reorderLevel;
   }
   public void setReorderLevel(int reorderLevel) {
       this.reorderLevel = reorderLevel;
   }
   public void buy(int b) {//Buy stocks of value b
       setStockLevel(getStockLevel() + b);
   }
   public void restock(int stock) {
       setStockLevel(stock);
   }
   public void warning() {
       if(getStockLevel()            System.out.println("WARNING: Stock level is below the reorder level!");
       else {
           System.out.println("Stock level looks good!");
       }
   }
   @Override
   public String toString() {
       return "RetailItem [itemName=" + itemName + ", serialNumber=" + serialNumber + ", unitPrice=" + unitPrice
               + ", stockLevel=" + stockLevel + ", reorderLevel=" + reorderLevel + "]";
   }
  
  
  
}

import java.util.Date;
import java.util.concurrent.TimeUnit;

public class PerishableItems extends RetailItem{

   private Date expiryDate;
   private String storageInstructions;
   private int consumeDeadline;
   public PerishableItems(String itemName, String serialNumber, int unitPrice, int stockLevel, int reorderLevel,
           Date expiryDate, String storageInstructions, int consumeDeadline) {
       super(itemName, serialNumber, unitPrice, stockLevel, reorderLevel);
       this.expiryDate = expiryDate;
       this.storageInstructions = storageInstructions;
       this.consumeDeadline = consumeDeadline;
   }
   public Date getExpiryDate() {
       return expiryDate;
   }
   public void setExpiryDate(Date expiryDate) {
       this.expiryDate = expiryDate;
   }
   public String getStorageInstructions() {
       return storageInstructions;
   }
   public void setStorageInstructions(String storageInstructions) {
       this.storageInstructions = storageInstructions;
   }
   public int getConsumeDeadline() {
       return consumeDeadline;
   }
   public void setConsumeDeadline(int consumeDeadline) {
       this.consumeDeadline = consumeDeadline;
   }
   public int daysExpiry() {
       int diff = (int) (new Date().getTime() - getExpiryDate().getTime());
        return (int) TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);
   }
   @Override
   public String toString() {
       return "PerishableItems [expiryDate=" + expiryDate + ", storageInstructions=" + storageInstructions
               + ", consumeDeadline=" + consumeDeadline + ", getItemName()=" + getItemName() + ", getSerialNumber()="
               + getSerialNumber() + ", getUnitPrice()=" + getUnitPrice() + ", getStockLevel()=" + getStockLevel()
               + ", getReorderLevel()=" + getReorderLevel() + "]";
   }
  
  
}

import java.util.Date;

public class Test {

   public static void main(String[] args) {
       RetailItem item1 = new RetailItem("Laptop", "ABC001", 40000, 1000, 500);
       RetailItem item2 = new RetailItem("Mobile", "ABC002", 30000, 1200, 700);
       PerishableItems item3 = new PerishableItems("Milk", "P001", 40, 500, 100, new Date(), "Store in cool place", 2);
       PerishableItems item4 = new PerishableItems("Bread", "P002", 400, 5000, 1000, new Date(), "Do not heat it", 5);
       PerishableItems item5 = new PerishableItems("Noodles", "P003", 50, 400, 100, new Date(), "Store in dry place", 7);
      
       System.out.println("Stock level for item 1= "+item1.getStockLevel());
       System.out.println("Stock level for item 2= "+item2.getStockLevel());
      
       int totalValue = item1.getUnitPrice() + item2.getUnitPrice() + item3.getUnitPrice() +item4.getUnitPrice() +item5.getUnitPrice();
      
       System.out.println("Stock values = "+totalValue);
      
       item1.restock(1000);
       item2.restock(2000);
       item3.restock(3000);
      
       System.out.println("After restocking:\n");
       System.out.println(item1);
       System.out.println(item2);
       System.out.println(item3);
      
      
   }
}

Sample output:

Stock level for item 1= 1000
Stock level for item 2= 1200
Stock values = 70490
After restocking:

RetailItem [itemName=Laptop, serialNumber=ABC001, unitPrice=40000, stockLevel=1000, reorderLevel=500]
RetailItem [itemName=Mobile, serialNumber=ABC002, unitPrice=30000, stockLevel=2000, reorderLevel=700]
PerishableItems [expiryDate=Wed Oct 18 19:50:25 IST 2017, storageInstructions=Store in cool place, consumeDeadline=2, getItemName()=Milk, getSerialNumber()=P001, getUnitPrice()=40, getStockLevel()=3000, getReorderLevel()=100]


Related Solutions

a) Design a Java Class which represents a Retail Item. It is to have the following fields
 a) Design a Java Class which represents a Retail Item. It is to have the following fields  Item Name  Item Serial No  Item Unit Price  Item Stock Level  Item Reorder Level  It is to have at least the following methods an Observer, Mutator and a Display method for each field. It is also to have a buy and a restock method and a method to issue a warning if the stock level goes below the re-order level.    b) Extend...
Write a java class called circle that represents a circle. It should have following three fields:...
Write a java class called circle that represents a circle. It should have following three fields: int x (x-coordinate), int y (y-coordinate), double radius (radius of the circle). Your circle object should have following methods: public int getRadius () public int getX () public int getY () public double area () public double perimeter() public String toString() write a client program called CircleClient that creates objects of the circle class called c1 and c2. Assign values to the fields when...
In java, design a class named Motorcycle that has the following fields: • year – The...
In java, design a class named Motorcycle that has the following fields: • year – The year field is an int that holds the motorcycle’s year • make – The make field references a String object that holds the make of the motorcycle. • speed – The speed field is an int that holds the motorcycle’s current speed The class should have the following constructor and other methods: • Constructor – the constructor should accept the motorcycle’s year and make...
Java... Design a Payroll class with the following fields: • name: a String containing the employee's...
Java... Design a Payroll class with the following fields: • name: a String containing the employee's name • idNumber: an int representing the employee's ID number • rate: a double containing the employee's hourly pay rate • hours: an int representing the number of hours this employee has worked The class should also have the following methods: • Constructor: takes the employee's name and ID number as arguments • Accessors: allow access to all of the fields of the Payroll...
Design a class named Pet, which should have the following fields: Name – The name field...
Design a class named Pet, which should have the following fields: Name – The name field holds the name of a pet. Type – The type field holds the type of animal that is the pet. Example values are “Dog”, “Cat”, and “Bird”. Age – The age field holds the pet’s age. The Pet class should also have the following methods: setName – The setName method stores a value in the name field. setType – The setType method stores a...
Write a Java class called Person. The class should have the following fields: A field for...
Write a Java class called Person. The class should have the following fields: A field for the person’s name. A field for the person’s SSN. A field for the person’s taxable income. A (Boolean) field for the person’s marital status. The Person class should have a getter and setter for each field. The Person class should have a constructor that takes no parameters and sets the fields to the following values: The name field should be set to “unknown”. The...
Write a java program using the following information Design a LandTract class that has two fields...
Write a java program using the following information Design a LandTract class that has two fields (i.e. instance variables): one for the tract’s length(a double), and one for the width (a double). The class should have:  a constructor that accepts arguments for the two fields  a method that returns the tract’s area(i.e. length * width)  an equals method that accepts a LandTract object as an argument. If the argument object holds the same data (i.e. length and...
Design an Inventory class that can hold information for an item in a retail store’s inventory.
C++! Becareful following the test case.7. Inventory ClassDesign an Inventory class that can hold information for an item in a retail store’s inventory.The class should have the following private member variables.Variable Name   DescriptionitemNumber   An int that holds the item’s number.quantity               An int that holds the quantity of the item on hand.cost    A double that holds the wholesale per-unit cost of the itemThe class should have the following public member functionsMember Function               Descriptiondefault constructor             Sets all the member variables...
(Java) Design a class named Person with fields for holding a person’s name, address, and telephone...
(Java) Design a class named Person with fields for holding a person’s name, address, and telephone number. Write one or more constructors and the appropriate mutator and accessor methods for the class’s fields. Next, design a class named Customer, which extends the Person class. The Customer class should have a field for a customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write one or more constructors and the appropriate mutator and...
JAVA - Design and implement a class called Flight that represents an airline flight. It should...
JAVA - Design and implement a class called Flight that represents an airline flight. It should contain instance data that represent the airline name, the flight number, and the flight’s origin and destination cities. Define the Flight constructor to accept and initialize all instance data. Include getter and setter methods for all instance data. Include a toString method that returns a one-line description of the flight. Create a driver class called FlightTest, whose main method instantiates and updates several Flight...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT