vendredi 27 janvier 2017

user input string and int, if statements

I'm new to java and I'm working on some homework. I am trying to write an 'If' statement, by with a string and int. What is supposed to happen is the user inputs gender, today's date, and their birthday. Then the program is supposed to tell you if you're a male and you're a certain age, the best rate of you is... But, what I'm having trouble is, how do I write an 'If' statement with int and a string?

the //comments were given by my professor

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.");
  }

Aucun commentaire:

Enregistrer un commentaire