Advertisement
Richard_Sekol

ex3.10

Oct 2nd, 2014
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. package ch3;
  2.  
  3. public class producttester {
  4.  
  5. public static void main(String[] args) {
  6. // TODO Auto-generated method stub
  7. product lightBulb = new product("Light Bulb", 29.99);
  8. lightBulb.getName();
  9. lightBulb.getPrice();
  10. lightBulb.reducePrice(5);
  11. lightBulb.getPrice();
  12. product carrot = new product("carrot", 19.99);
  13. carrot.getName();
  14. carrot.getPrice();
  15. carrot.reducePrice(5);
  16. carrot.getPrice();
  17. }
  18.  
  19. }
  20.  
  21. ********************************************************************************************************************************
  22.  
  23. package ch3;
  24.  
  25. public class product {
  26.  
  27. private String product;
  28. private double price;
  29. public product(String productName, double productPrice){
  30. product = productName;
  31. price = productPrice;
  32. }
  33. public void getName(){
  34. System.out.println(product);
  35. }
  36. public void getPrice(){
  37. System.out.println(price);
  38. }
  39. public void reducePrice(double discount){
  40. double reduce = discount;
  41. price = price - reduce;
  42. }
  43.  
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement