Hallo, ich bin jetzt mal so frei und lade die Aufgabenstellung hoch. Das wäre zuviel Text zum abschreiben. Kann mir bitte jemand bei der Lösung erklären, es geht um die Printstatistics-Methode ganz unten:
Die letzte System.out.print Anweisung verstehe ich überhaupt nicht. Wieso heisst es"user.equalAttributes(comp)" ?? Wo kommt denn "user" her? Nirgends im Programm steht etwas von user und wieso wird hier der Wert "comp" an die Methode übergeben?
Die letzte System.out.print Anweisung verstehe ich überhaupt nicht. Wieso heisst es"user.equalAttributes(comp)" ?? Wo kommt denn "user" her? Nirgends im Programm steht etwas von user und wieso wird hier der Wert "comp" an die Methode übergeben?
Java:
public class Shape{
char color;
char type;
}
Shape (char type, char, color){
this.color=color;
this.type=type;
}
Shape(){
int zufall=(int)(Math.random()*3);
if (zufall==0)[
this.color='red'
}
if(zufall==1){
this.color='blue'
}
if(zufall==2){
this.color='green'
}
int zufall2=(int)(Math.random()*2);
if (zufall2==1){
this.type='r'
}
if (zufall2==2){
this.type='a'
}
}
public double equalAttributes(Shape Comp){
double equal=0.0;
if(this.color==comp.color){
equal=0.5;
}
if(this.color==comp.type){
equal=1.0;
}
}
public static void printStatistics(Shape comp, Shape user){
System.out.println("Statistik");
System.out.println("Computer");
comp.printShape();
System.out.println("Deine Wahl");
user.printShape();
System.out.print("Übereinstimmung"+user.equalAttributes(comp)*100 +"%");
//Die letzte System.out.print Anweisung verstehe ich überhaupt nicht. Wieso heisst es"user.equalAttributes(comp)" ?? Wo kommt denn "user" her? Nirgends im Programm steht etwas von user und wieso wird hier der Wert "comp" an die Methode übergeben?