Я новичок в java, и я работаю над домашней работой. Я пытаюсь написать оператор «If», с помощью строки и int. Что должно произойти, пользователь вводит пол, сегодняшнюю дату и день рождения. Тогда программа должна сказать вам, если вы мужчина, и вы достигли определенного возраста, самый лучший из вас - это ... Но у меня возникают проблемы, как написать «Если 'с int и строкой?пользовательская строка ввода и int, если утверждения
// в комментарии были даны моим профессором
Scanner kb = new Scanner(System.in);
System.out.println("Welcome to the car renter's rate finder.");
System.out.print("Please enter the renter's gender (m/f): ");
String gender = kb.nextLine();
System.out.print("Please enter the today's date (mm dd yyyy): ");
int curMonth = kb.nextInt();
int curDay = kb.nextInt();
int curYear = kb.nextInt();
kb.nextLine();
System.out.print("Please enter the renter's date of birth (mm dd yyyy): ");
int birthMonth = kb.nextInt();
int birthDay = kb.nextInt();
int birthYear = kb.nextInt();
kb.nextLine();
int age = 0;
String rateResult;
// Get age...
age = calcAge(curMonth, curDay, curYear, birthMonth, birthDay, birthYear);
// Get the rental rate...
//rateResult = calcRateClass(age, gender);
// Display the results...
//displayResults(gender, age, rateResult);
displayResults(age);
}
}
private static int calcAge(int curMonth, int curDay, int curYear,int, birthMonth,int birthDay,int birthYear)
{
return curYear - birthYear;
}
private static void displayResults(int age)
{
System.out.printf("Thanks. \n");
System.out.printf("The driver is %d years old. \n",age);
if (age >= 35 && age <= 65)
//Best rate (male drivers, age 33 – 65 and female drivers, age 30 - 62) -- $40.00 per day, $200.00 per week
{
System.out.println("$40.00 per day, $200.00 per week.");
}
'если (gender.equalsIgnoreCase ("М") && (возраст> = 35 && возраст <= 65)) {... } ' – MadProgrammer
@MadProgrammer: ради читаемость: 'if (gender.equalsIgnoreCase (" M ") && (35 <= age && age <= 65)) {...}' –
@MichaelLihs Лично мне нравится, как он читает сейчас '> = && <= «визуально показывает« между »намерениями, но это я, и я просто соображаю;) – MadProgrammer