我编写的代码需要3个用户输入,年龄,无事故驾驶的年份和性别,然后将它们传递给各种方法来操纵输入。 在输入性别之前,代码已终止。它打印 “输入性别为男性/女性”,但在我给出答案之前终止,您能告诉我为什么这样做吗?我正在使用Eclipse。
import java.util.Scanner;
public class Retry1 {
static double Cost = 0;
public static double MaleInsurance(int NoClaims, String gender, int age) {
if(gender.equals("male")&& age> 20 && age<75)
Cost = (1700-( NoClaims * 0.1));
return Cost;
}
public static double FemaleInsurance(int NoClaims, String gender, int age){
if(gender.equals("female")&& age < 25 && age> 20)
Cost = 1500 - (NoClaims*0.1);
return Cost; }
public static double FemaleInsuraceV2(int NoClaims, String gender, int age) {
if(gender.equals("female")&& age>25 && age<75)
Cost = 800 - (NoClaims*0.1);
return Cost;
}
public static void demographic(int age){
if(age < 20 || age >75)
System.out.print("demographic not eligible for insurance");
}
public static void main(String[]args) {
Scanner info = new Scanner(System.in);
System.out.print("Enter age: ");
int age = info.nextInt();
System.out.print("Enter years accident free, maximum of 5: ");
int NoClaims = info.nextInt();
System.out.print("Enter gender male/female: ");
String gender = info.nextLine();
info.close();
FemaleInsuraceV2(NoClaims, gender, age);
FemaleInsurance(NoClaims, gender, age);
MaleInsurance(NoClaims, gender, age);
demographic(age);
}
}