新游乐场开张,收费标准如下: 1.70岁以上不收费。 2.69-55 三折 (海南户口二折); 3.54-16 全价(海南户口七折); 4.15-7 五折(海南户口四折); 5.6岁及以下不收费。 6.军人在以上优惠的基础上减半。 游乐场门票全价100元。 请编写小程序计算票价,每一个游客提供他的年龄,户口,是否是军人信息 用java编写
时间: 2023-03-21 12:01:07 浏览: 94
我可以给你一个简单的示例,可以帮助你编写小程序计算门票票价:public class TicketPrice { public static double calculatePrice(int age, String residency, boolean military) {
double price = 100.0; if (age >= 70) {
price = 0;
} else if (age >= 55) {
price *= 0.7;
if (residency.equals("Hainan")) {
price *= 0.2;
}
} else if (age >= 16) {
if (residency.equals("Hainan")) {
price *= 0.7;
}
} else if (age >= 7) {
price *= 0.5;
if (residency.equals("Hainan")) {
price *= 0.4;
}
} else {
price = 0;
} if (military) {
price *= 0.5;
} return price;
}
}