Question: /** * Title: Blue-Green Game * Description: This application takes a String value with any combination of * Bs and Gs and places each character

/** *Title: Blue-Green Game
*Description: This application takes a String value with any combination of * Bs and Gs and places each character in a class variable myArray in the order * they occur in the input String. Then the array is sorted, so all Bs proceed * all Gs. The sorting is done by maintaining two positions in the array.
*Copyright: CCBIT University of Massachusetts Amherst Copyright (c) 2003
*Company: University of Massachusetts Amherst
* @author Robbie Moll * @version 1.0 */ public class MyGame { //Blue and Green chars private static final char BLUE = 'B'; private static final char GREEN = 'G'; //place holder for Bs and Gs private char[] myArray; //the counter for the swaps private int swapCount; //sample test cases private String BG1 = "BGBGGGBBGGBGB"; private String BG2 = "BBBGGGBGBGBBB"; private String BG3 = "BGBGBBBGBGB"; private String BG4 = "GB"; private String BG5 = "BG"; //the constructor public MyGame() { } //initializes the array with the given string value public void initGame(String sequence){ swapCount = 0; myArray = new char[sequence.length()]; for(int i=0; iNotice that the MyGame class includes an integer attribute called swapCount (see link below)./JavaCS1/src/colorgame/MyGame.java swapCount is initialized to 0 in the initGame method. Suppose we add the line System.out.println("The swap count is " +game, swapCount); to the main method, as we've done below, so that main prints the number of swaps made during the sort. public static void main(String[] args) {MyGame game = new MyGame(); game.initGame(game.BG1); game.sortArray(); game.printArray(); System.out.println("The swap count is " + game.swapCount);/ew line} Modify the sortArray method so that the alteration we've added to main prints the correct value. Notice that we've inserted the original sortArray method body in the answer box below. Example: if the input sequence is "GBBBBBBB", the altered version of main (above) should print: The swap count is 1 private int swapCount; public void sortArray () {1 int beginP = 0; 2 int endP = myArray.length-1; 3 while(beginP
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
