I'm just starting to learn Java, and I'm stuck on a section in the conditionals and control flow part of Codecademy.
I'm trying to add a method that manipulates the shippingCost
variable if shipped outside of "California". I'm really not sure how to expand on top of that (let me know if there are any questions), but I'm confused as to how to do this, or is it just too advanced for the section I'm on?
This is one of my first posts, so if I'm using any features wrong let me know.
public class Order {
boolean isFilled;
double billAmount;
String shipping;
public Order(boolean filled, double cost, String shippingMethod, int zip) {
if (cost > 24.00) {
System.out.println("High value item!");
} else {
System.out.println("Low value item!");
}
isFilled = filled;
billAmount = cost;
shipping = shippingMethod;
}
public void ship() {
if (isFilled) {
System.out.println("Shipping");
} else {
System.out.println("Order not ready");
}
double shippingCost = calculateShipping();
System.out.println("Shipping cost: ");
System.out.println(shippingCost);
}
public double calculateShipping() {
double shippingCost;
switch (shipping) {
case "Regular":
shippingCost = 0;
break;
case "Express":
shippingCost = 1.75;
break;
default:
shippingCost = .50;
}
return shippingCost;
}
// customer address
public void address(int streetNumber, String streetName, String town, String city, String state, int zipCode){
double shippingCost;
if (state != "California"){
shippingCost += 10;
}
}
public static void main(String[] args) {
// create instances and call methods here!
}
}
For this, I'm getting this message:
Order.java:54: error: variable shippingCost might not have been initialized
shippingCost += 10;
^
1 error