Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. /*
  2. * Diclaimer: This is a class that assumes that
  3. * the carport is acctually composed of just the same part.
  4. * Imagine a lego with hundreds of the same lego brick.
  5. * We assume that the price of a single part is 50 kr.
  6. * This class is neither SOLID nor tested well enough.
  7. *
  8. * What is this class supposed to at the end of the project: It will calculate
  9. * all the need parts, and it will return a list of all of the individula parts
  10. * their exact number, single and total price(of a batch of the same part),
  11. * as well the final price of all of them, according to their value in
  12. * the database;
  13. */
  14. package Utilities;
  15.  
  16. /**
  17. *
  18. * @author Casper
  19. */
  20. public class CarportCalculator {
  21.  
  22. double wigth;
  23. double length;
  24. boolean isFlat; // This valuse is used to check if the rooftop is falt or not.
  25.  
  26. public CarportCalculator(double wigth, double length, boolean isFlat) {
  27. this.wigth = wigth;
  28. this.length = length;
  29. this.isFlat = isFlat;
  30. }
  31.  
  32. /*
  33. This method calculate the final price of the shed, based on all the parts
  34. that will be needed to build the carport, accordin to its wight and lenght.
  35. We assume that a single part costs 50 kr. In case the roof is nonflat (naming ?)
  36. We call a separate method to calculate those prices ass well.
  37. */
  38. public double calculatePrice(){
  39. double priceOfAPart = 50;
  40.  
  41. return (calculateParts() * priceOfAPart);
  42. }
  43.  
  44.  
  45. /*
  46. Used to calculate the needed parts. Can be called later, to list the exact
  47. number of parts
  48. */
  49. public int calculateAllParts(){
  50. if (!isFlat){
  51. return (calculateParts() + calculateBigRoofParts());
  52. }
  53. return calculateParts();
  54. }
  55. /*
  56. This method calculate the parts need under the assumption, that each
  57. single meter of length it will take 10 parts to build, while each single
  58. meter of wigth will take 30 parts to build.
  59. The Math.ceil(Double n) rounds a double number to the next round double.
  60. For example a double value of 2.1 will return 3.0 , but a value of 4.0
  61. will stay 4.0. And then we cast it to int. We do this, to make sure, that the
  62. client of the company will get the extra parts, that they will need to "cut"
  63. */
  64. public int calculateParts(){
  65.  
  66. double lengthParts, wightParts = 0;
  67. lengthParts = (length * 20); // adding 0.5 to be abble to add
  68. wightParts = (wigth * 20);
  69. return ((int)Math.ceil(lengthParts + wightParts));
  70. }
  71.  
  72.  
  73. /*
  74. This method is used to calculate the numbers of parts, that will be needed
  75. for the non-flat (names ?) rooftop. It assumes that each square meter takes
  76. the same amount of parts to build.
  77. Math.ceil is used again, for the same reason as in the previous class.
  78. */
  79. public int calculateBigRoofParts(){
  80. double sizeOfRoof = wigth * length;
  81. int partsPerSquareMeter = 100;
  82.  
  83. /*
  84. The 0.5 allue is added to
  85. */
  86. return (int) Math.ceil(sizeOfRoof * partsPerSquareMeter);
  87. }
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement