java 这题怎么做!那几天上课请假了 没学到if 请大神解答!
发布网友
发布时间:2022-05-02 13:09
我来回答
共1个回答
热心网友
时间:2022-06-20 04:58
public class Ticket{
private float price = 5000;
public float getPrice(int month, int cabin){
float discount = 0;
if (month >= 4 && month <= 10) {
if (cabin==1) {
discount = 0.9f;
}else{
discount = 0.5f;
}
}else{
if (cabin==1) {
discount = 0.8f;
}else{
discount = 0.4f;
}
}
return price * discount;
}
public static void main(String[] args) {
Ticket test = new Ticket();
System.out.println("4月旺季要去海南旅游:头等仓标价:" + test.getPrice(4, 1));
System.out.println("10月旺季要去海南旅游:经济仓标价:" + test.getPrice(10, 2));
System.out.println("3月淡季要去海南旅游:头等仓标价:" + test.getPrice(3, 1));
System.out.println("11月淡季要去海南旅游:经济仓标价:" + test.getPrice(11, 2));
}
}