Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Lab (95 points) ! The objective of Lab 6 is to create a new variation of the Spi

ID: 3545529 • Letter: L

Question

Lab (95 points)!
The objective of Lab 6 is to create a new variation of
the Spinner game you created in Lab 5 as an object-oriented solution. To aid your learning, you will be asked to create four incremental versions of the game. As you move from version to version, some of the classes will be copied and renamed, while others will remain intact to be reused by multiple versions of your game. This is intended to demonstrate reuse of these components, a key benefit of object-oriented programming.

Spin Game Version 1 (15 points)

In version 1, you will create the game in a class called SpinGame1 which does not have a main method. Create another class classed GameTester1 with a main method that includes the following code:

Using the following UML model as a guide, create the SpinGame1 class with the three attributes and two methods shown in the model below. Set the playerName to a value of your choice and initialize the playScore to zero. Also create a Random instance to be used by the spin method.

public static void main(String[] args) {

SpinGame1 game = new SpinGame1();

sg.playGame(); }

"

1"

CSE"1341"

The objective of Lab 6 is to create a new variation of the Spinner game you created in Lab 5 as an object-oriented solution. To aid your learning, you will be asked to create four incremental versions of the game. As you move from version to version, some of the classes will be copied and renamed, while others will remain intact to be reused by multiple versions of your game. This is intended to demonstrate reuse of these components, a key benefit of object-oriented programming. Spin Game Version 1 In version 1, you will create the game in a class called SpinGame1 which does not have a main method. Create another class classed GameTester1 with a main method that includes the following code: Using the following UML model as a guide, create the SpinGame1 class with the three attributes and two methods shown in the model below. Set the playerName to a value of your choice and initialize the playScore to zero. Also create a Random instance to be used by the spin method.

Explanation / Answer

class GameTester1

{

public static void main(String args[]) throws Exception

{

new SpinGame1().playGame();

}

}


______________________________________________________________________________________________


import java.util.*;

import java.io.*;



class SpinGame1

{


String playerName;


int playerScore;


Random randomMaker;



public SpinGame1()


{


playerName="Fred";


playerScore=0;


randomMaker=new Random();


}


public void playGame()


{


for(int i=0;i<5;i++)


{


System.out.println("ROUND "+(i+1));


int count=0;


while(true)


{


int spin=spin();


System.out.print(spin+" ");


count++;



if(spin==5)


{


break;


}


}


playerScore=playerScore+count;


System.out.println("Round "+(i+1)+" is over");


System.out.println(playerName+ "'s score is now "+playerScore);


}


}


public int spin()


{


return randomMaker.nextInt(10)+1;


}


}