Informatiker Board (http://www.informatikerboard.de/board/index.php)
- Themengebiete (http://www.informatikerboard.de/board/board.php?boardid=1)
--- Theoretische Informatik (http://www.informatikerboard.de/board/board.php?boardid=5)
---- Logik (http://www.informatikerboard.de/board/board.php?boardid=16)
----- Java - Anfängeraufgabe (http://www.informatikerboard.de/board/thread.php?threadid=2516)


Geschrieben von SixFeetUnder am 29.10.2015 um 04:39:

  Java - Anfängeraufgabe

Meine Frage:
Hallo,

folgende CodingBat - Aufgabe, wo mir Probleme bereitet:

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

Meine Ideen:
code:
1:
2:
3:
4:
5:
6:
7:
public int dateFashion(int you, int date) 
{
   return (you>=8 && date >=8)?2:1;
}



Mein Code stimmt so natürlich nicht, aber ich kann doch nicht mit drei aufeinander folgenden if-Abfragen programmieren?



Geschrieben von SixFeetUnder am 29.10.2015 um 05:12:

 

Hab es jetzt weiterhin versucht, aber so ganz will es noch nicht funktionieren. Hier mal mein aktueller Code:

code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
public int dateFashion(int you, int date)  
{
if (you>=8 || date>=8)   
{      
   return 2;    
}   
else if (you<=2 || date<=2)   
 {       
   return 0;   
}   
else     
{
    return 1;     
 }



Geschrieben von eulerscheZahl am 29.10.2015 um 06:04:

 

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

Du musst erst <=2 prüfen. Ansonsten sollte dein Code passen, eben einfach die Reihenfolge der if tauschen.


Forensoftware: Burning Board, entwickelt von WoltLab GmbH