I am writing a Java program to decide how much a user has to pay for a delivery charge for a school project. I have been advised the method that works out the cost has to be static. When i de-bug my code the value of the price is never changing and i don't know why, please see my code below.
main method
package questionOne;
import java.util.Scanner;
import questionOne.DeliveryMenu;
public class DeliveryMenuDemo {
public static void main(String[] args)
throws java.io.IOException {
String choice;
DeliveryMenu d = new DeliveryMenu();
System.out.println("Enter the type of Delivery service needed (Standard/Super/WowWee)?");
Scanner scanner = new Scanner(System.in);
choice = scanner.next();
d.setDeliveryCost(choice);
d.getPrice();
}
}
and class with other methods
package questionOne;
public class DeliveryMenu {
private static String delivery;
private static int price=0;
public static int setDeliveryCost(String choice) {
if(delivery == "Standard") {
price = price + 22;
} else if (delivery == "Super") {
price = price + 44;
} else if (delivery == "wow-wee") {
price = price + 60;
}
return price;
}
public String setDelivery(String s) {
return delivery=s;
}
public void getPrice() {
System.out.println(price);
}
}
price is never changing to the desired amount.