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...
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 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...
JAVA/Netbeans •Design a class named Person with fields for holding a person’s name, address and phone...
JAVA/Netbeans •Design a class named Person with fields for holding a person’s name, address and phone number (all Strings) –Write a constructor that takes all the required information. –Write a constructor that only takes the name of the person and uses this to call the first constructor you wrote. –Implement the accessor and mutator methods. Make them final so subclasses cannot override them –Implement the toString() method •Design a class named Customer, which extends the Person class. It should have...
Java Solution Create a class hierarchy that represents shapes. It should have the following classes: Shape,...
Java Solution Create a class hierarchy that represents shapes. It should have the following classes: Shape, Two Dimensional Shape, Three Dimensional Shape, Square, Circle, Cube, Rectangular Prism, and Sphere. Cube should inherit from Rectangular Prism. The two dimensional shapes should include methods to calculate Area. The three dimensional shapes should include methods to calculate surface area and volume. Use as little methods as possible (total, across all classes) to accomplish this, think about what logic should be written at which...
Design a class named Employee. The class should keep the following information in fields: ·         Employee...
Design a class named Employee. The class should keep the following information in fields: ·         Employee name ·         Employee number in the format XXX–L, where each X is a digit within the range 0–9 and the L is a letter within the range A–M. ·         Hire date Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named ProductionWorker that inherits from the Employee class. The ProductionWorker class should have fields...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT