Advertisement
Guest User

Untitled

a guest
Oct 24th, 2012
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1.  
  2. public class ShippingCharges {
  3.  
  4. //data members
  5. // are the basic characteristics of the object
  6. private double packageWeight;
  7. private double miles;
  8. // private double shippingCharge;
  9.  
  10.  
  11.  
  12. //method members
  13. //are the functionalities of the object
  14.  
  15. //constructors These methods create (instantiate) an instance of the object
  16.  
  17. /**
  18. * Default constructor sets the xcoor to 0, the ycoor to 0, and the radius to 0
  19. */
  20. public ShippingCharges(){
  21. packageWeight = 0;
  22. miles = 0;
  23. // shippingCharge = 0;
  24.  
  25. }
  26.  
  27. /**
  28. * full constructor sets the packageWeight and the miles according to the parameters
  29. * @param pw is the Package Weight
  30. * @param m is the Miles Traveled
  31. */
  32. public ShippingCharges(double pw, double m){
  33. this.packageWeight = pw;
  34. this.miles = m;
  35.  
  36. }
  37.  
  38. //getters
  39.  
  40. /**
  41. * this method returns the packageWeight
  42. * @return the packageWeight
  43. */
  44. public double getpackageWeight(){
  45. return packageWeight;
  46. }
  47.  
  48.  
  49. /**
  50. * this method returns the miles
  51. * @return the miles
  52. */
  53. public double getmiles(){
  54. return miles;
  55. }
  56.  
  57. // /**
  58. // * this method returns the shippingCharge
  59. // * @return the shippingCharge
  60. // */
  61. // public double getshippingCharge() {
  62. // return shippingCharge;
  63. // }
  64.  
  65.  
  66.  
  67. //setters
  68.  
  69. /**
  70. * This method resets the Xcoor, Ycoor, and Radius according to the parameter
  71. * @param value will be set as the new value
  72. */
  73. public void setpackageWeight( double value ) {
  74. this.packageWeight = value;
  75. }
  76.  
  77. public void setmiles( double value ) {
  78. this.miles = value;
  79. }
  80.  
  81. // public void setshippingCharge( double value ) {
  82. // this.shippingCharge = value;
  83. // }
  84.  
  85.  
  86.  
  87. //toString method
  88.  
  89. public String toString(){
  90. String str;
  91.  
  92. str = ("Shipping Charges: Package Weight - " + packageWeight
  93. + " Miles shipped - " + miles);
  94. return str;
  95. }
  96.  
  97. //all other object specific methods
  98. double chargedMiles, shippingCharge;
  99.  
  100. public double chargedMiles() {
  101. return Math.ceil((double) miles/500);
  102. }
  103.  
  104. public double shippingCharge(){
  105. if (packageWeight <= 2 && packageWeight > 0) {
  106. shippingCharge = chargedMiles * 1.10;
  107. }
  108. else if(packageWeight <= 6) {
  109. shippingCharge = chargedMiles * 2.20;
  110. }
  111. else if(packageWeight <= 10) {
  112. shippingCharge = chargedMiles * 3.70;
  113. }
  114. else {
  115. shippingCharge = chargedMiles * 4.80;
  116. }
  117. return shippingCharge;
  118.  
  119. }
  120.  
  121.  
  122. }//end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement