Code: Select all
// class definition - to simulate and create a Dice class and execute its methods
class Dice
{
// properties
int dotCount = 1; // initializing the dice to show side with 1 dot for testing
// show the number of dots that the dice is showing
void showDots(){
System.out.println("Number of dots: " + dotCount);
}
// simulate rolling of dice
void rollDice(){
dotCount = 5; // value assigned to simulate roll dice. TODO Use Random later
System.out.println("Dice Rolled");
}
public static void main (){
Dice obj = new Dice();
obj.showDots();
obj.rollDice();
obj.showDots();
}
}
Code: Select all
Dice.main();
Anzahl der Punkte: 1
Gewürfelte Würfel
Anzahl der Punkte: 5
Wenn ich jedoch die Zeile ersetze:
Code: Select all
public static void main ()
Code: Select all
public static void main (String args[])
| Dice.main();
Symbol kann nicht gefunden werden
Symbol: Variable Dice
Welches Argument muss ich in Dice.main() angeben? damit es im zweiten Fall läuft? Ich habe Dice.main({""}) ausprobiert, es hat nicht funktioniert.