Java > Logic-1 > dateFashion (CodingBat Solution)

Problem:

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).

dateFashion(5, 10) → 2
dateFashion(5, 2) → 0
dateFashion(5, 5) → 1


Solution:

public int dateFashion(int you, int date) {
  if ((you >= 8 && date > 2) || (date >= 8 && you > 2))
    return 2;
  if (you <= 2 || date <= 2)
    return 0;
  else
    return 1;
}


3 comments :

  1. public int dateFashion(int you, int date) {
    if((you >= 8 || date >= 8) && !(you <= 2 || date <= 2)) {
    return 2;
    }
    else if (you <= 2 || date <= 2) {
    return 0;
    }
    else {
    return 1;
    }

    }

    ReplyDelete
  2. public int dateFashion(int you, int date) {
    if(you <= 2 ||date <= 2){
    return 0;
    }
    if(you <= 7 && date <= 7){
    return 1;
    }
    return 2;
    }

    ReplyDelete
  3. public int dateFashion(int you, int date) {
    if (you <= 2 || date <= 2) return 0;
    if (you <= 7 && date <= 7) return 1;
    return 2;
    }

    ReplyDelete

Follow Me

If you like our content, feel free to follow me to stay updated.

Subscribe

Enter your email address:

We hate spam as much as you do.

Upload Material

Got an exam, project, tutorial video, exercise, solutions, unsolved problem, question, solution manual? We are open to any coding material. Why not upload?

Upload

Copyright © 2012 - 2014 Java Problems  --  About  --  Attribution  --  Privacy Policy  --  Terms of Use  --  Contact