Allen Li
Allen Li

Reputation: 499

Java dateFishion coding

I got a java if-statement problem which is You and your date are trying to get a table at a restaurant. The parameter "you" is the stylishness of your clothes, in the range 0..10, and "date" is the stylishness of your date's clothes. The result getting the table is encoded as an int value with 0=no, 1=maybe, 2=yes. If either of you is very stylish, 8 or more, then the result is 2 (yes). With the exception that if either of you has style of 2 or less, then the result is 0 (no). Otherwise the result is 1 (maybe).

After I plug in my code to the compiler there are something wrong with my code.

Here is my code

enter image description here

For this problem I don't what condition should the date be via if-statement.

Upvotes: 0

Views: 1030

Answers (1)

Vasu
Vasu

Reputation: 22422

if either of you has style of 2 or less, then the result is 0 (no)

To handle this, you don't need to check >=8 for you and date variables in your first condition, rather it should be as shown below:

if(you<=2 || date<=2) {//just check date or you <=2
  return 0;
} else if(you>=8 || date>=8) {
  return 2;
} else {
   return 0;
}

Upvotes: 1

Related Questions