Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ShippingCharges {
- //data members
- // are the basic characteristics of the object
- private double packageWeight;
- private double miles;
- // private double shippingCharge;
- //method members
- //are the functionalities of the object
- //constructors These methods create (instantiate) an instance of the object
- /**
- * Default constructor sets the xcoor to 0, the ycoor to 0, and the radius to 0
- */
- public ShippingCharges(){
- packageWeight = 0;
- miles = 0;
- // shippingCharge = 0;
- }
- /**
- * full constructor sets the packageWeight and the miles according to the parameters
- * @param pw is the Package Weight
- * @param m is the Miles Traveled
- */
- public ShippingCharges(double pw, double m){
- this.packageWeight = pw;
- this.miles = m;
- }
- //getters
- /**
- * this method returns the packageWeight
- * @return the packageWeight
- */
- public double getpackageWeight(){
- return packageWeight;
- }
- /**
- * this method returns the miles
- * @return the miles
- */
- public double getmiles(){
- return miles;
- }
- // /**
- // * this method returns the shippingCharge
- // * @return the shippingCharge
- // */
- // public double getshippingCharge() {
- // return shippingCharge;
- // }
- //setters
- /**
- * This method resets the Xcoor, Ycoor, and Radius according to the parameter
- * @param value will be set as the new value
- */
- public void setpackageWeight( double value ) {
- this.packageWeight = value;
- }
- public void setmiles( double value ) {
- this.miles = value;
- }
- // public void setshippingCharge( double value ) {
- // this.shippingCharge = value;
- // }
- //toString method
- public String toString(){
- String str;
- str = ("Shipping Charges: Package Weight - " + packageWeight
- + " Miles shipped - " + miles);
- return str;
- }
- //all other object specific methods
- double chargedMiles, shippingCharge;
- public double chargedMiles() {
- return Math.ceil((double) miles/500);
- }
- public double shippingCharge(){
- if (packageWeight <= 2 && packageWeight > 0) {
- shippingCharge = chargedMiles * 1.10;
- }
- else if(packageWeight <= 6) {
- shippingCharge = chargedMiles * 2.20;
- }
- else if(packageWeight <= 10) {
- shippingCharge = chargedMiles * 3.70;
- }
- else {
- shippingCharge = chargedMiles * 4.80;
- }
- return shippingCharge;
- }
- }//end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement