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

During each round, players choose a move, which may be either Kipple, Bipple, Gi

ID: 3736315 • Letter: D

Question

During each round, players choose a move, which may be either Kipple, Bipple, Gipple, or Vipple. The rules are: * Kipple beats Bipple and Gipple * Bipple beats Gipple Gipple beats Vipple Vipple beats Kipple and Bipple The computer wins in the event of a tie The rules should be printed to the screen The user is asked if they'd like to play a round o if they choose 'y', a round is played o if they choose 'n', the program ends Until the user has chosen to quit, another round is played In a round of play: o The user is asked to enter a move, which may be either 'B', 'G, 'K, or 'V'. The program should continue to prompt the user until a valid move is entered o The computer makes a move at random. (Hint: remember how we generated random numbers in class.) o The program prints the computer's move, the user's move, and who is the winner of this round o The user is asked if they'd like to continue When the user has decided to quit the game, the program prints the number of o rounds played o times the user won o times the computer won Break up the problem into at least 5 methods separate from main(). Develop and submit JUnit tests for at least two of these Recall that to create most of the skeleton of these tests for yourself, in Netbeans you can right-click (CMD-click on a Mac) on name of your Java source file in the project view, then Tools, then Create/Update Tests. The test file may then be found under the Test Packages folder. Some functions that we've used that should be helpful are: assertEquals assertTrue assertFalse

Explanation / Answer

Answer :)

BGKVGame
package com.example;
import java.util.Random;
import java.util.Scanner;
import org.apache.commons.lang3.ArrayUtils;
public class BGKVGame {
public static void main(String[] args) {
System.out.println("The rules are :");
System.out.println("Kipple beats Bipple and Gipple");
System.out.println("Bipple beats Gipple");
System.out.println("Gipple beats Vipple");
System.out.println("Vipple beats Kipple and Bipple");
System.out.println("The computer wins in case of a tie");
BGKVGame bgkvGame=new BGKVGame();
System.out.println("Do you like to play a round ? (y/n)");
Scanner sc=new Scanner(System.in);
String ch=sc.next();
int user=0,computer=0;
while(ch.equalsIgnoreCase("y")){
char[] moves={'K','B','G','V'};
System.out.println("Please enter a move : (B/G/K/V)");
char move=bgkvGame.changeCharacterToUppercase(sc.next().charAt(0));
while(bgkvGame.validateUserMove(moves, move)==false){
System.out.println("Invalid move. Please enter a move : (B/G/K/V)");
move=sc.next().charAt(0);
}
Random r = new Random();
char computerMove=moves[r.nextInt(moves.length)];
String winner="";
switch(move){
case 'K' :
if(computerMove=='B' || computerMove =='G'){
user++;
winner="User";
}
else{
computer++;
winner="Computer";
}
break;
case 'B' :
if(computerMove=='G'){
user++;
winner="User";
}
else{
computer++;
winner="Computer";
}
break;
case 'G':
if(computerMove=='V'){
user++;
winner="User";
}
else{
computer++;
winner="Computer";
}
break;
case 'V':
if(computerMove=='B' || computerMove =='K'){
user++;
winner="User";
}
else{
computer++;
winner="Computer";
}
break;
}
System.out.println("User move : "+move);
System.out.println("Computer move : "+computerMove);
System.out.println("Winner of this round : "+winner);
System.out.println("Do you like to play again ? (y/n)");
ch=sc.next();
bgkvGame.isUserWillingtoPlay(ch);
}
System.out.println();
System.out.println("Rounds played : "+bgkvGame.totalRoundsPlayed(user,computer));
System.out.println("Number of rounds user won : "+user);
System.out.println("Number of rounds computer won : "+computer);
System.out.println("Final winner of Series : "+bgkvGame.finalWinnerOfAllRounds(user,computer));
sc.close();
}
public String finalWinnerOfAllRounds(int user, int computer) {
if(user>computer)
return "User";
return "Computer";
}
public char changeCharacterToUppercase(char c) {
return Character.toUpperCase(c);
}
public boolean isUserWillingtoPlay(String ch) {
if(ch=="y")
return true;
return false;
}
public boolean validateUserMove(char[] moves, char move) {
if(ArrayUtils.contains(moves, move))
return true;
return false;
}
public String totalRoundsPlayed(int user, int computer) {
return (user+computer)+"";
}
}

Output :

The rules are :
Kipple beats Bipple and Gipple
Bipple beats Gipple
Gipple beats Vipple
Vipple beats Kipple and Bipple
The computer wins in case of a tie
Do you like to play a round ? (y/n)
y
Please enter a move : (B/G/K/V)
b
User move : B
Computer move : B
Winner of this round : Computer
Do you like to play again ? (y/n)
y
Please enter a move : (B/G/K/V)
g
User move : G
Computer move : V
Winner of this round : User
Do you like to play again ? (y/n)
y
Please enter a move : (B/G/K/V)
v
User move : V
Computer move : K
Winner of this round : User
Do you like to play again ? (y/n)
n

Rounds played : 3
Number of rounds user won : 2
Number of rounds computer won : 1
Final winner of Series : User

Junit :

package com.example;

import org.junit.Assert;
import org.junit.Test;

public class TestBGKVGame {

@Test
public void testFinalWinnerOfAllRounds(){
BGKVGame bgkvGame=new BGKVGame();
Assert.assertEquals(bgkvGame.finalWinnerOfAllRounds(1, 2), "Computer");
}

@Test
public void testTotalRoundsPlayed(){
BGKVGame bgkvGame=new BGKVGame();
Assert.assertEquals(bgkvGame.totalRoundsPlayed(3, 4), 7);
}

@Test
public void testValidateUserMove(){
BGKVGame bgkvGame=new BGKVGame();
char[] moves={'B','K','G','V'};
char move='K';
Assert.assertTrue(bgkvGame.validateUserMove(moves, move));
}

@Test
public void testValidateUserMoveNegative(){
BGKVGame bgkvGame=new BGKVGame();
char[] moves={'B','K','G','V'};
char move='S';
Assert.assertFalse(bgkvGame.validateUserMove(moves, move));
}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote