question archive You are hired by Expressimo Delivery Service to develop an application that computes the delivery charge

You are hired by Expressimo Delivery Service to develop an application that computes the delivery charge

Subject:Computer SciencePrice:4.89 Bought3

You are hired by Expressimo Delivery Service to develop an application that computes the delivery charge. The company allows two types of packaging-letter and box-and three types of service-Next Day Priority, Next Day Standard, and 2-Day. The following table shows the formula for computing the charge:
The program will input three values from the user: type of package, type of service, and weight of the package.

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE

Answer Preview

* © Blackcompe

*

* Pricing Scheme

* _______________

*

* Letter:

*

* $12 upto 8 oz and $1.75 per oz thereafter for two day

* $22 upto 8 oz and $1.75 per oz thereafter for next day standard

* $32 upto 8 oz and $1.75 per oz thereafter for next day priority

*

* Box:

*

* $13.75 for the first lb and $15.75 per lb thereafter for two day

* $23.75 for the first lb and $15.75 per lb thereafter for next day standard

* $33.75 for the first lb and $15.75 per lb thereafter for next day priority

*/

 

import java.util.ArrayList;

public class DeliveryService

{

ArrayList packages = null;

 

DeliveryService()

{

packages = new ArrayList();

}

 

public void add(Package p)

{

packages.add(p);

}

 

public String toString()

{

String s = "Package\t\tType\t\t" +

"Delivery\t\tWeight\t\tPrice\n\n";

 

for(int i = 0; i < packages.size(); i++)

{

s += packages.get(i).toString() + "\n";

}

return s;

}

 

static class Package

{

static final int LETTER = 1;

static final int BOX = 2;

final int TYPE;

Shipping shipping;

final double weight;

double price;

 

Package(final int T, Shipping s, double w)

{

TYPE = T;

shipping = s;

weight = w;

setPrice();

}

 

private void setPrice()

{

if(shipping.getType() == Shipping.TWODAY)

{

if(TYPE == LETTER)

{

if(weight <= 8.0)

{

price = 12.00;

}

else

{

double over = weight - 8.0;

price = 12.00 + (1.75 * over);

}

}else if(TYPE == BOX)

{

if(weight <= 1.0)

{

price = 13.75;

}

else

{

double over = weight - 1.0;

price = 13.75 + (15.75 * over);

}

}

}else if(shipping.getType() == Shipping.NEXTDAY_STANDARD)

{

if(TYPE == LETTER)

{

if(weight <= 8.0)

{

price = 22.00;

}

else

{

double over = weight - 8.0;

price = 22.00 + (1.75 * over);

}

}else if(TYPE == BOX)

{

if(weight <= 1.0)

{

price = 23.75;

}

else

{

double over = weight - 1.0;

price = 23.75 + (15.75 * over);

}

}

}else if(shipping.getType() == Shipping.NEXTDAY_PRIORITY)

{

if(TYPE == LETTER)

{

if(weight <= 8.0)

{

price = 32.00;

}

else

{

double over = weight - 8.0;

price = 32.00 + (1.75 * over);

}

}else if(TYPE == BOX)

{

if(weight <= 1.0)

{

price = 33.75;

}

else

{

double over = weight - 1.0;

price = 33.75 + (15.75 * over);

}

}

}

}

 

public double getPrice()

{

return price;

}

 

public String toString()

{

String s = "";

if(TYPE == LETTER)

{

s += "\t\tLetter";

}else if(TYPE == BOX)

{

s += "\t\tBox";

}

s += shipping.toString();

if(TYPE == LETTER)

{

s += "\t" + weight + " oz";

}

else if(TYPE == BOX)

{

s += "\t" + weight + " lb(s)";

}

if(shipping.TYPE == Shipping.TWODAY)

{

double p = price * 100;

int discarded = (int)p;

price = (double)discarded/100;

s += "\t$" + price;

}

else

{

double p = price * 100;

int discarded = (int)p;

price = (double)discarded/100;

s += "\t\t$" + price;

}

return s;

}

}

 

static class Shipping

{

static final int NEXTDAY_PRIORITY = 1;

static final int NEXTDAY_STANDARD = 2;

static final int TWODAY = 3;

final int TYPE;

 

Shipping(final int T)

{

TYPE = T;

}

 

public int getType()

{

return TYPE;

}

 

public String toString()

{

if(TYPE == NEXTDAY_PRIORITY)

{

return "\t\tNext Day Priority";

}else if(TYPE == NEXTDAY_STANDARD)

{

return "\t\tNext Day Standard";

}else if(TYPE == TWODAY)

{

return "\t\tTwo Day\t\t";

}

else

{

return null;

}

}

}

 

public static void main(String[] args)

{

DeliveryService serv = new DeliveryService();

 

Shipping s1 = new Shipping(Shipping.NEXTDAY_PRIORITY);

Package p1 = new Package(Package.LETTER, s1, 8.0);

Shipping s2 = new Shipping(Shipping.TWODAY);

Package p2 = new Package(Package.BOX, s2, 1.2);

Shipping s3 = new Shipping(Shipping.NEXTDAY_STANDARD);

Package p3 = new Package(Package.LETTER, s3, 12.2);

 

serv.add(p1);

serv.add(p2);

serv.add(p3);

 

System.out.println(serv);

}

}