Prompt for the weight of a parcel and determine and display the delivery charge for the parcel. The delivery charge is calculated based on the following table.
Parcel weight (kg) Cost per kg ($)
Less than 2.5 $3.50 per kg
Between 2.5 kg and 5 kg $2.85 per kg
Greater than 5 kg $2.45 per kg
能不能简单写
我没学过
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
只用if else 和 double就行
这三个是导入的包,用来读输入的。如果你实在是不知道这个,可以用Scanner代替。
public static void main(String[] args) {
// TODO 自动生成方法存根
System.out.println("please input the weight:");
Scanner cin = new Scanner(System.in);
double weight=cin.nextDouble();
double money_paid=paid(weight);
System.out.println("You should pay :"+money_paid);
}
但是使用的时候也需要导入import java.util.Scanner;这个包
设置包裹的重量并且顯示郵寄費用。郵寄費計算表如下:
重量(kg) 每kg價格
小於2.5kg $3.5/kg
2.5-5kg $2.85/kg
5kg以上 $2.45/kg