Respuesta :
Using the knowledge in computational language in JAVA it is possible to write a code that generate random numbers in a game
Writting the code in JAVA:
public class GameSpinner {
int spinner;
int num;
int current;
public GameSpinner(int spinner) {
super();
this.spinner = spinner;
this.current = 0;
this.num = 0;
}
public int spin() {
int curr = 1 + (int) (Math.random() * spinner);
if (this.current == 0 || this.num == 0) {
this.current = 1;
this.num = curr;
return curr;
}
if (this.num == curr) {
this.current = this.current + 1;
return curr;
} else {
this.num = curr;
this.current = 1;
return curr;
}
}
public int currentRun() {
return this.current;
}
}
GameSpinnerTest.java
public class GameSpinnerTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
GameSpinner g = new GameSpinner(4);
System.out.println("g.currentRun() : "+g.currentRun());
System.out.println("g.spin() : "+g.spin());
System.out.println("g.currentRun() : "+g.currentRun());
System.out.println("g.spin() : "+g.spin());
System.out.println("g.currentRun() : "+g.currentRun());
System.out.println("g.spin() : "+g.spin());
System.out.println("g.currentRun() : "+g.currentRun());
System.out.println("g.spin() : "+g.spin());
System.out.println("g.currentRun() : "+g.currentRun());
System.out.println("g.spin() : "+g.spin());
System.out.println("g.spin() : "+g.spin());
System.out.println("g.spin() : "+g.spin());
System.out.println("g.currentRun() : "+g.currentRun());
}
}
Output
g.currentRun() : 0
g.spin() : 1
g.currentRun() : 1
g.spin() : 4
g.currentRun() : 1
g.spin() : 4
g.currentRun() : 2
g.spin() : 3
g.currentRun() : 1
g.spin() : 3
g.spin() : 2
g.spin() : 2
g.currentRun() : 2
See more about JAVA at brainly.com/question/12975450
#SPJ1

