Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me:( I need help writing a custom mastermind program with Java. Not looking for a generic mastermind, but one that has the following

Please help me:( I need help writing a custom mastermind program with Java. Not looking for a generic mastermind, but one that has the following requirements:

1. Mastermind.java (already provided- contains main())

import.java.util.Scanner;

public class Mastermind { public static void main(String[] args)

{

Scanner input = new Scanner(System.in); MastermindPuzzle mp; int easyHard; int puzzleNum;

System.out.print("1=easy, 2=hard? "); easyHard = input.nextInt(); System.out.println();

System.out.print("Puzzle num? "); puzzleNum = input.nextInt(); System.out.println();

if (easyHard == 1) { mp = new EasyMastermindPuzzle(); }

else { mp = new HardMastermindPuzzle(); }

mp.startGame(puzzleNum);

char[] guess = new char[mp.getNumPieces()];

while (mp.stillPlaying()) { System.out.print("Guess? "); for (int i = 0; i < guess.length; i++)

{ guess[i] = (input.next()).charAt(0); }

System.out.println(); mp.makeGuess(guess);

System.out.printf("%20d %d --> ", mp.getLastCorrectColorCount(), mp.getLastCorrectPositionCount());

for (int i = 0; i < guess.length; i++) { System.out.print(guess[i]); System.out.print(' '); }

System.out.println();

}

if (mp.won()) { System.out.println("Congratulations!"); }

else

{ System.out.println("Sorry, you lost"); }

} }

2. 2. MastermindPuzzle.java

//private instance variables

//abstract

//implement Winnable interface

//default constructor

//getNumPieces needs to return an integer with the number of pegs in a puzzle (currently 4 - use constants)

//chooseSolution should accept an integer that is the puzzle to choose (1-3 or -1 for random)

//call chooseSolution

//reset your other variables that remember the state of the current game

//makeGuess accepts a character array with the letters to check

//increase the number of guesses made, and set 2 instance variables that indicate the number of correctly colored pegs and the number in the correct position

//getLastCorrectColorCount needs to return the number of pegs that are the correct color in the last guess

//getLastCorrectPositionCount needs to return the number of pegs that are in the correct position in the last guess

3. EasyMastermindPuzzle.java (subclass of MastermindPuzzle)

//This class ONLY needs constructor(s) and chooseSolution //chooseSolution should do the following:

//If the parameter is 1, set the puzzle to R, G, B, W

//If the parameter is 2, set the puzzle to P, R, W, Y

//If the parameter is 3, set the puzzle to W, B, Y, P

//If the parameter is -1, set the puzzle to random colors (4 out of R, G, B, W, Y, P)

4. HardMastermindPuzzle.java (subclass of MastermindPuzzle)

//This class ONLY needs constructor(s) and chooseSolutionchooseSolution should do the following:

//If the parameter is 1, set the puzzle to R, G, B, R

//If the parameter is 2, set the puzzle to P, R, P, Y

//If the parameter is 3, set the puzzle to W, W, Y, P

//If the parameter is -1, set the puzzle to random colors (4 out of R, G, B, W, Y, P) with at least 1 duplicate color within in the puzzle

5. Winnable.java

//This should have 3 methods each returns a boolean: won, lost, stillPlaying

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

PC Magazine Guide To Client Server Databases

Authors: Joe Salemi

1st Edition

156276070X, 978-1562760700

More Books

Students also viewed these Databases questions