Advertisement
Guest User

act

a guest
Jun 30th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. College of Computer Studies
  2. Laboratory Activity Form
  3.  
  4. Course Number CCS 227
  5. Course Title OOP in Java
  6. Topics Covered: Class definition, toString(), equals(Object obj)
  7. Objectives: Implement a class in Java
  8. Description
  9.  
  10. Create a class called Product for representing a certain item for sale in a grocery store.
  11. • Each object of class Product should include the following data members:
  12. • An integer product code
  13. • A String representing the name of the product
  14. • A float value representing the unit cost of the product
  15. • An integer value representing the number of items on stock.
  16.  
  17. • Try to include a static data member called counter which is initially 1, every time a new product is created, the value of counter is used as the product code, then the counter is incremented.
  18.  
  19. • Include a constructor with the ff. signature.
  20. Product(String name,float cost,int stock)
  21. • name is the name of the product, cost is the unit cost and stock is the initial number of stock (inventory). (Example, there are 10 safeguard soap each costing 20.00)
  22.  
  23. • Include the following methods:
  24.  
  25. public int getCode();
  26. public String getName();
  27. public float getCost();
  28. public int getStock();
  29.  
  30. public boolean sell(int count)
  31. • Used to sell a product. count represents the number of items to be bought. Note that the number of items should be checked and decreased if it is sufficient with the number of items to be bought. This represents the sale of this product, represents a decrease in inventory.
  32. • This method returns true if there is sufficient stock available, otherwise should return false.
  33.  
  34. public void purchase(int count)
  35. • Allows the operator of the business to purchase additional stock – an increase in inventory. The parameter passed increases stock on hand.
  36.  
  37. public void priceIncrease(float rate)
  38. • Increases the cost of a product based on the parameter rate (percentage).
  39.  
  40. public String toString()
  41. • Returns a string representation of the Product
  42.  
  43. public boolean equals(Object obj)
  44. • Two products are equal if they have the same code and the same name
  45.  
  46. In order to test the Product class, include a simple main method that creates a Product object and calls the different methods of the class.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement