Advertisement
Sheero

RetailItem

Apr 26th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. //Zehra Baig
  2. //CSC 162-01
  3. //Lab 6-C
  4.  
  5. public class RetailItem
  6. {
  7.     //Fields
  8.     private String description;
  9.     private int unitsOnHand;
  10.     private double price;
  11.    
  12.     //Default Constructor
  13.     public RetailItem()
  14.     {
  15.         description = "";
  16.         unitsOnHand = 0;
  17.         price = 0.0;
  18.     }
  19.    
  20.     //Overloaded Constructor
  21.     public RetailItem(String desc, int units, double p)
  22.     {
  23.         description = desc;
  24.         unitsOnHand = units;
  25.         price = p;
  26.     }
  27.    
  28.     //sets description of RetailItem object, accepts String as arg
  29.     public void setDescription(String d)
  30.     {
  31.         description = d;
  32.     }
  33.    
  34.     //sets units on hand of RetailItem object, accepts int as arg
  35.     public void setUnitsOnHand(int u) throws NegativeUnitsException
  36.     {
  37.         //if u is negative then throw NegativeUnitsException
  38.         if (u < 0)
  39.         {
  40.             throw new NegativeUnitsException(u);
  41.         }
  42.         unitsOnHand = u;
  43.     }
  44.    
  45.     //sets price of RetailItem object, accepts double as arg
  46.     public void setPrice(double p) throws NegativePriceException
  47.     {
  48.         //if p is negative then throw NegativePriceException
  49.         if (p < 0)
  50.         {
  51.             throw new NegativePriceException(p);
  52.         }
  53.         price = p;
  54.     }
  55.    
  56.     //retrieves and returns description of RetailItem object
  57.     public String getDescription()
  58.     {
  59.         return description;
  60.     }
  61.    
  62.     //retrieves and returns units on hand of RetailItem object
  63.     public int getUnitsOnHand()
  64.     {
  65.         return unitsOnHand;
  66.     }
  67.    
  68.     //retrieves and returns price of RetailItem object
  69.     public double getPrice()
  70.     {
  71.         return price;
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement