Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In java i need to write a code that i can use to calculate shipping cost, i am going to be using that code for

In java i need to write a code that i can use to calculate shipping cost, i am going to be using that code for a project in android studio but i am having a hard time finding where to start. All i have left to do is to calculate the dimensions of a package and then calculate the shipping cost:

Instructions:

length x width x height, in whole number of inches. The package size will affect the base cost only. If all three dimensions are no more than 12 inches, there is no change to the base cost. If the largest dimension is over 12 inches but no more than 24 inches, the base cost will be doubled. If the largest dimension is over 24 inches, the base cost will be three times as much as the current amount. The initial and default package size should be set to 12 x 12 x 12.

Shipping Cost:

Express, Standard, or Ground. There is no change in the cost calculation for ground shipping. For standard shipping service, both the base cost and the added cost will be doubled. For express service, the base cost and added cost will be tripled. Use Standard shipping as the initial and default service for cost calculation.

The code i have already calculates base cost and weight fees here is my code so far:

package com.cornez.shippingcalculator; /**  * Created by trishcornez on 6/29/14.  */ public class ShipItem { // SHIPPING CONSTANTS static final Double BASE = 3.00; static final Double ADDED = .50; static final int BASE_WEIGHT = 16; static final double EXTRA_OUNCES = 4.0; // DATA MEMBERS private Integer mWeight; private Double mBaseCost; private Double mAddedCost; private Double mTotalCost; public ShipItem() { mWeight = 0; mAddedCost = 0.0; mBaseCost = BASE; mTotalCost = 0.0; } public void setWeight (int weight){ mWeight = weight; computeCosts(); } private void computeCosts() { mAddedCost = 0.0; mBaseCost = BASE; if (mWeight <= 0) mBaseCost = 0.0; else if (mWeight > BASE_WEIGHT) mAddedCost = Math.ceil((double) (mWeight - BASE_WEIGHT) / EXTRA_OUNCES) * ADDED; mTotalCost = mBaseCost + mAddedCost; } public Double getBaseCost() { return mBaseCost; } public Double getAddedCost() { return mAddedCost; } public Double getTotalCost() { return mTotalCost; } } 
 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

Students also viewed these Databases questions