Advertisement
Flaron

udemy_33. CarpetCostCalculator

Sep 19th, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. public class Floor {
  2. private double width;
  3. private double length;
  4.  
  5. public Floor(double width, double length) {
  6. if (width<0)
  7. this.width=0;
  8. else
  9. this.width = width;
  10. if (length<0)
  11. this.length = 0;
  12. else
  13. this.length=length;
  14. }
  15.  
  16. public double getArea(){
  17. return width*length;
  18. }
  19. }
  20.  
  21. public class Carpet {
  22. private double cost;
  23.  
  24. public Carpet(double cost) {
  25. if (cost<0)
  26. this.cost = 0;
  27. else
  28. this.cost=cost;
  29. }
  30.  
  31. public double getCost() {
  32. return cost;
  33. }
  34. }
  35.  
  36. public class Calculator {
  37. private Floor floor;
  38. private Carpet carpet;
  39.  
  40. public Calculator(Floor floor, Carpet carpet) {
  41. this.floor = floor;
  42. this.carpet = carpet;
  43. }
  44.  
  45. public double getTotalCost(){
  46. return floor.getArea()*carpet.getCost();
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement