0% found this document useful (0 votes)
8 views17 pages

Java Order Class with Shipping Logic

The document contains a Java class named 'Order' that manages order details including whether an order is filled, the bill amount, and the shipping method. It includes methods to ship the order and calculate shipping costs based on the shipping method. The main method creates two order instances and attempts to ship them, demonstrating the functionality of the class.

Uploaded by

khan.md.usaidali
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views17 pages

Java Order Class with Shipping Logic

The document contains a Java class named 'Order' that manages order details including whether an order is filled, the bill amount, and the shipping method. It includes methods to ship the order and calculate shipping costs based on the shipping method. The main method creates two order instances and attempts to ship them, demonstrating the functionality of the class.

Uploaded by

khan.md.usaidali
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

public class Order {

boolean isFilled;
double billAmount;
String shipping;

public Order(boolean filled, double cost, String shippingMethod) {


if (cost > 24.00) {
[Link]("High value item!");
}
isFilled = filled;
billAmount = cost;
shipping = shippingMethod;
}

public void ship() {


if (isFilled) {
[Link]("Shipping");
[Link]("Shipping cost: " + calculateShipping());
} else {
[Link]("Order not ready");
}
}

public double calculateShipping() {


// declare conditional statement here

public static void main(String[] args) {


// do not alter the main method!
Order book = new Order(true, 9.99, "Express");
Order chemistrySet = new Order(false, 72.50, "Regular");

[Link]();
[Link]();
}
}
public class Order {
boolean isFilled;
double billAmount;
String shipping;
String couponCode;

public Order(boolean filled, double cost, String shippingMethod, String coupon) {


if (cost > 24.00) {
[Link]("High value item!");
}
isFilled = filled;
billAmount = cost;
shipping = shippingMethod;
couponCode = coupon;
}

public void ship() {


if (isFilled) {
[Link]("Shipping");
[Link]("Shipping cost: " + calculateShipping());
} else {
[Link]("Order not ready");
}
}

public double calculateShipping() {


if ([Link]("Regular")) {
return 0;
} else if ([Link]("Express")) {
// Add your code here

} else {
return .50;
}
}

public static void main(String[] args) {


// do not alter the main method!
Order book = new Order(true, 9.99, "Express", "ship50");
Order chemistrySet = new Order(false, 72.50, "Regular", "freeShipping");

[Link]();
[Link]();
}
}

You might also like