嘿,我一直在做这个任务,而且我已经撞墙了,不知道现在从哪里开始,但我需要付出代价来匹配每种方法中的每个重量类别。然后需要使用价格来生成增值税和总量。
public class Delivery_Details
{
private static String Timestamp;
private static String tChoice;
private static String wChoice;
private static String cChoice;
private static int price;
private static int vat;
public static int total;
public static void main(String[] args) {
townChoices();
weightChoices();
courierChoices();
printDetails();
}
public static void printDetails()
// printDetails() method will display Report
{
System.out.println("DELIVERY REPORT - " + "created on " + Timestamp);
System.out.println("*************************************************");
System.out.println("TOWN: " + tChoice);
System.out.println("WEIGHT:" + wChoice);
System.out.println("PRICE:" + " $`enter code here`" + price);
System.out.println("VAT (14%):" + vat);
System.out.println("TOTAL DUE:" + total);
System.out.println("COURIER:" + cChoice);
System.out.println("*************************************************");
}
private static void time()
{
Timestamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime());
}
private static void townChoices() {
String[] town = new String[3];
town[0] = "CAPE TOWN";
town[1] = "PRETORIA";
town[2] = "DURBAN";
Object selectedTown = JOptionPane.showInputDialog(null,"Choose town for parcel to be delivered to:", "Town options", JOptionPane.QUESTION_MESSAGE,null,town, "CAPE TOWN");
tChoice = selectedTown.toString();
}
private static void weightChoices()
{
String[] weight = new String[3];
weight[0] = "0kg - 4kg";
weight[1] = "5kg - 9kg";
weight[2] = "Over 10kg";
Object selectedTown = JOptionPane.showInputDialog(null,"Select the weight category of the parcel to be delivered to:"+ tChoice, "Town options", JOptionPane.QUESTION_MESSAGE,null,weight, "CAPE TOWN");
wChoice = selectedTown.toString();
price = Integer.parseInt(wChoice);
if(wChoice.equals(weight[0]))
{
price = 300;
}
if(wChoice.equals(weight[1]))
{
price = 500;
}
if(wChoice.equals(weight[2]))
{
price = 700;
}
}
private static void courierChoices()
{
String[] courier = new String[3];
courier[0] = "ABC Couriers";
courier[1] = "Fast Track";
courier[2] = "Rest Assured";
Object selectedTown = JOptionPane.showInputDialog(null,"Select the courier company to deliver the parcel of weight" + wChoice + "to" + tChoice, "Town options", JOptionPane.QUESTION_MESSAGE,null,courier, "CAPE TOWN");
cChoice = selectedTown.toString();
}
public static void vatAndtoal()
{
vat = price * 14/100;
total = price + vat;
}
}
以下是我收到的例外情况:
Exception in thread "main" java.lang.NumberFormatException: For input string: "0kg - 4kg"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.lang.Integer.parseInt(Integer.java:615)
at delivery_details.Delivery_Details.weightChoices(Delivery_Details.java:77)
at delivery_details.Delivery_Details.main(Delivery_Details.java:31)