Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone code this program? Mastermind assignment 3 core package Codebreaker class Add private method consoleAttempt() that will allow for backend testing of the logic,

Can someone code this program?

Mastermind assignment 3

core package

Codebreaker class

Add private method consoleAttempt() that will allow for backend testing of the logic, it shall do the following:

Remove previous data stored in member variable codebreakerAttempt (Hint: class ArrayList has a handy method . removeAll())

Instantiate an instance of class Scanner to take input from the console

Prompt the user to enter their guess, my implementation was as follows:

System.out.println(" Enter your colors in left to right order " +

"Use BLUE, BLACK, ORANGE, WHITE, YELLOW, RED, GREEN, PINK:");

Loop until the user enters four valid colors with no duplicatesInstantiate an instance of class String set equal to Scanners method next()Evaluate the users input (Hint: recommend using either String method .toUpperCase() or .toLowerCase() to alleviate issues with case sensitivity)If the entered color matches one of the eight valid colors of the game, do the following:

Output to the console the selected color

Add the color to the member variable codebreakerAttempt

If the size of the codebreakerAttempt is less than the max pegs specified in our Constants.java file then add a prompt to enter for the user their next color

Using an enhanced for loop output to the console the codebreakers attempt

Update method getCodebreakerAttempt() to call method consoleAttempt()

Codemaker class

Update method signature checkAttemptedCode () to match the modified method signature in interface ICodemaker

Implement method checkAttemptedCode() to do the following:

Create local variables to store the number of red and white pegs scored by the codebreaker

Create a local variable to store which pegs have been evaluated of the codebreakers guess

Create a local variable to convert the secret code Set member variable to an ArrayList object

Check if the codebreakers guess is exactly equal to the codemakers attempt (Hint: class ArrayList has a handy method .equals())

If true, then red pegs should equal 4

If true, then white pegs should equal 0

If item d. fails, then determine which pegs are the correct color in the correct position or the correct color in the wrong positionLoop through the max pegs as defined in our Constants.java classCheck if a correct color is in the correct position by comparing index to index of the two ArrayLists representing the secret code and the codebreakers guess

If true, increment the red peg counter

Add the codebreakers guess at this index to the Set that stores the evaluated pegs

Use an enhanced for loop using the codebreakers attempt as the collection objectCheck if the secret code ArrayList contains the current element of the codebreakers attempt (Hint: class ArrayList has a handy method .contains())Loop through the max pegs as defined in our Constants.java classCheck if the secret code ArrayList is NOT equal to the codebreakers attempt at the specific index AND the secret code ArrayList contains the codebreakers attempt at the specific index AND the pegs evaluated Set does NOT include the current codebreakers attempt at the specific index

If true, then increment the white pegs counter

Add the current index of the codebreakers attempt to the ArrayList that stores the evaluated pegs

Evaluate the red and white peg counters to populate the codemakers response

For each red peg, add to the member variable codemakerResponse Color.RED

For each white peg, add to the member variable codemakerResponse Color.WHITE

Red is always first, then white!

Use an enhanced for loop to output to the console the codemaerkers response

Game class

Modify custom constructor

Call method play()

Method play()Loop for the max number of attempts as defined in our Constants.java class AND the codebreaker hasnt guessed the secrete code

Instantiate an instance of class ArrayList specified as using class Color, set equal to calling method getCodebreakerAttempt() in class Codebreaker

Call method checkAttemptedCode() in class Codemaker, passing the local variable from step a. as an argument

Instantiate an instance of class ArrayList specified as using class Color, set equal to calling method getCodemakerResponse () in class Codemaker

Use an enhanced for loop to output to the console the codemakers response for each codebreakers attempt

ICodebreaker interface

package core;

// Imports import java.awt.Color; import java.util.ArrayList;

public interface ICodebreaker { /// Method Signatures public void checkCode(ArrayList attempt); }

ICodemaker interface

Modify method signature public void checkAttemptedCode()

Add parameter ArrayList attempt to the method signature

package core;

// Imports import java.awt.Color; import java.util.ArrayList;

public interface ICodemaker { /// Method Signatures public void generateSecretCode(ArrayList codeColors); public void checkAttemptedCode(); }

IGame interface

package core;

public interface IGame { /// Method Signatures public void play(); }

userInterface package

package userInterface;

public class MasterMindUi { }

MasterMindUi class

package userInterface;

public class MasterMindUi { }

MasterMind application

Test Case 1

Test Case 1 passes regression testing

Source compiles with no errors

Source runs with no errors

Source includes comments

Perform the following test cases

Test Cases

Action

Expected outcome

Test Case 1

Run application start the game

JOptionPane.showMessageDialog() displays similar to figure 1

Test Case 2

Run application codemaker generates secret code

The console window should be similar to figure 2

Java does NOT automatically translate its Color objects to a String value, rather it prints the RGB code of the color.

Test Case 3

Run application codebreaker prompted for their guess

The console window should be similar to figure 3

Test Case 4

Run application codebreaker entries acknowledged

The console window should be similar to figure 4

Test Case 5

Run application codemaker response

The console window should be similar to figure 5

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

More Books

Students also viewed these Databases questions

Question

Write Hund's rule?

Answered: 1 week ago

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago