Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Zehra Baig
- //CSC 162-01
- //Lab 6-C
- public class RetailItem
- {
- //Fields
- private String description;
- private int unitsOnHand;
- private double price;
- //Default Constructor
- public RetailItem()
- {
- description = "";
- unitsOnHand = 0;
- price = 0.0;
- }
- //Overloaded Constructor
- public RetailItem(String desc, int units, double p)
- {
- description = desc;
- unitsOnHand = units;
- price = p;
- }
- //sets description of RetailItem object, accepts String as arg
- public void setDescription(String d)
- {
- description = d;
- }
- //sets units on hand of RetailItem object, accepts int as arg
- public void setUnitsOnHand(int u) throws NegativeUnitsException
- {
- //if u is negative then throw NegativeUnitsException
- if (u < 0)
- {
- throw new NegativeUnitsException(u);
- }
- unitsOnHand = u;
- }
- //sets price of RetailItem object, accepts double as arg
- public void setPrice(double p) throws NegativePriceException
- {
- //if p is negative then throw NegativePriceException
- if (p < 0)
- {
- throw new NegativePriceException(p);
- }
- price = p;
- }
- //retrieves and returns description of RetailItem object
- public String getDescription()
- {
- return description;
- }
- //retrieves and returns units on hand of RetailItem object
- public int getUnitsOnHand()
- {
- return unitsOnHand;
- }
- //retrieves and returns price of RetailItem object
- public double getPrice()
- {
- return price;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement