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();
}
}
In Notebook, wenn der folgende Code in der nächsten Zelle ausgeführt wird:
Die Ausgabe ist wie erwartet:
Anzahl der Punkte: 1
Gewürfelte Würfel
Anzahl der Punkte: 5
Wenn ich jedoch die Zeile ersetze:
mit
Code: Select all
public static void main (String args[])
Ich erhalte die folgende Fehlermeldung:
| 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.
[code]// 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]
In Notebook, wenn der folgende Code in der nächsten Zelle ausgeführt wird:
[code]Dice.main();[/code]
[b]Die Ausgabe ist wie erwartet:[/b]
Anzahl der Punkte: 1
Gewürfelte Würfel
Anzahl der Punkte: 5
Wenn ich jedoch die Zeile ersetze:
[code]public static void main ()[/code]
mit
[code]public static void main (String args[])[/code]
Ich erhalte die folgende Fehlermeldung:
| 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.