Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment Scope : For this assignment students will begin developing the front end, or User Interface, portion of the MasterMind game. Based on my professional

Assignment Scope :

image text in transcribed

For this assignment students will begin developing the front end, or User Interface, portion of the MasterMind game. Based on my professional experience working in the industry I have always had to develop a UI for every application, therefore I translate that experience to students so they can have the same opportunity and be prepared professionally.

Typically, there is a one-to-one correlation of back end functionality to front end UI component. Depending upon the design of the application it doesnt always correlate perfectly, however with MasterMind, it works well.

Back-end functionality

Front-end UI component

Codemaker.java

CodemakerUi.java

Codebreaker.java

CodebreakerUi.java

Game.java

MasterMindUi.java

The goal is to develop the front-end components of the game MasterMind by creating classes:

CodebreakerUi.java

CodemakerUi.java

MasterMindUi.java

Students will also begin to learn writing simple ActionListeners or Event Handlers.

The UI will be developed in multiple assignments, it is not expected that for Assignment 4 the fully functioning UI is complete.

The image that follows is a prototype of what the UI will look like. It does not have to be an exact match. The rubric will provide guidance and recommendations on how to accomplish this, however feel free to be creative in developing the look and feel of the UI.

To accomplish this:

Reference the tasks below for the specifics of the source code requirements.

Compress a project and submit to Webcourses

Decompress compressed project and verify it is a Netbeans project

References

Netbeans.docx

Setting up a project in Netbeans.docx

Netbeans right click menu help.docx

Deliverables

To complete this assignment you must submit your compressed Netbeans project to Webcourses.

Please keep in mind that the tasks are guidance to accomplish the goals of the assignment. At times students will be required to do additional research (e.g. Google That S**T (GTS)!) to find implementation options. In the industry, software engineers are expected to be very self-sufficient to find the best solution for the task at hand.

I have provided multiple code examples on Webcourses that shows how to implement numerous of the tasks below, please reference those code examples prior to asking me for help!

Tasks and Rubric

Activity

mastermind package

Mastermind.java

Add to method main()

Instantiate an instance of class MastermindUi, passing the reference object of class Game as an argument

core package

Game.java

In the customer constructor, comment out the call the method play()

userInterface package

MastermindUi.java

Add member variables of type

Game game;

CodebreakerUi codebreakerUi;

CodemakerUi codemakerUi;

JFrame frame;

JMenuBar menuBar;

JMenu gameMenu;

JMenu helpMenu;

JMenuItem newGameMenuItem;

JMenuItem exitMenuItem;

JMenuItem aboutMenuItem;

JMenuItem rulesMenuItem;

A custom constructor should be defined that receives a parameter of type Game class

Set member variable of type class Game to the parameter passed in

Instantiate the member variable of class CodebreakerUi passing as an argument to the constructor the instance of class Codebreaker in class Game (hint: use the getter!)

Instantiate the member variable of class CodemakerUi passing as an argument to the constructor the instance of class Codemaker in class Game (hint: use the getter!)

call method initComponents()

A method initComponents() should initialize all the components for the UI and be called from the constructor

Set the default size of the JFrame

Set the default close operation of the JFrame

Use default layout manager BorderLayout

Set up the JMenuBar

i.JMenu Game should be added to the JMenuBar

ii.JMenuItems New Game and Exit should be added to the JMenu Game

iii.JMenu Help should be added to the JMenuBar

iv.JMenuItems About and Game Rules should be added to the JMenu Help

JMenuBar should be set on the JFrame

Add the CodemakerUi JPanels to the JFrame using the getters defined in the class

Add the CodebreakerUi JPanels to the JFrame using the getters defined in the class

Set the visibility of the JFrame (hint: this should ALWAYS be the last step on a UI)

Write an inner class to create an ActionListener that is registered to the JMenuItem with the text Exit; it should

Display a JOptionPane message confirming the user wants to exit using method showConfirmDialog()

If yes, exit the application by calling method System.exit() passing the value of 0 as an argument

If no, do not exit the application

Write an inner class to create an ActionListener that is registered to the JMenuItem with the text About using method showMessageDialog(); it should

Display a JOptionPane message informing the user:

Application name and version

Author

Date of development

Write an inner class to create an ActionListener that is registered to the JMenuItem with the text Game Rules using method showMessageDialog(); it should

Display a JOptionPane message informing the user:

Rules of the game as shown in Figure 6 below

CodebreakerUi.java

Add member variables of type:

JPanel codebreakerAttempt;

JPanel codebreakerColors;

Codebreaker codebreaker;

Create getters for the two JPanel member variables

A custom constructor should be defined that receives a parameter of type Codebreaker class

Set member variable of type class Codebreaker to the parameter passed in

call method initComponents()

A method initComponents() should initialize all the components for the UI and be called from the constructor

For each JPanel

i.Set the size of the JPanel using two methods to ensure the UI isnt too small

setMinimumSize()

setPreferredSize()

ii.Add a titled border for each using method

setBorder(BorderFactory.createTitledBorder("Codebreaker Attempt"));

This can be temporary, it just shows the layout while there arent any buttons or other components in the JPanels

CodemakerUi.java

Add member variables of type:

JPanel codemakerResponse;

JPanel secretCode;

Codebreaker codemaker;

Create getters for the two JPanel member variables

A custom constructor should be defined that receives a parameter of type Codebreaker class

Set member variable of type class Codemaker to the parameter passed in

call method initComponents()

A method initComponents() should initialize all the components for the UI and be called from the constructor

For each JPanel

i.Set the size of the JPanel using two methods to ensure the UI isnt too small

setMinimumSize()

setPreferredSize()

ii.Add a titled border for each using method

setBorder(BorderFactory.createTitledBorder("Codemaker Response"));

This can be temporary, it just shows the layout while there arent any buttons or other components in the JPanels

Mastermind application

Test Case 1

Test Case 1 passes

Test Case 2

Test Case 2 passes

Test Case 3

Test Case 3 passes

Source compiles with no errors

Source runs with no errors

Source includes comments

Total

Perform the following test cases

Test Cases

Action

Expected outcome

Test Case 1

Rregression Testing: Initial JOptionPane displays

JOptionPane is similar to figure 1

Test Case 2

Mastermind Initial UI displays

Mastermind UI looks similar figure 2

Test Case 3

Mastermind Game Menu

Game menu looks similar to figure 3

Test Case 4

Mastermind Help Menu

Help menu looks similar to figure 4

Test Case 5

About Menu Item Action Listener

JOptionPane displays similar to figure 5

Test Case 6

Rules Menu Item Action Listener

JOptionPane displays similar to figure 6

Test Case 7

Exit Menu Item Action Listener

JOptionPane displays similar to figure 7;

if user selects yes, the application should exit;

if user selects no, the application continues to run

Test Case 8

Project view

Project view matches figure 8

image text in transcribed

Figure 1 Test Case 1

image text in transcribed

Figure 2 Mastermind Initial UI

image text in transcribed

Figure 3 Game Menu

image text in transcribed

Figure 4 Help Menu

image text in transcribed

Figure 5 About Menu Item

image text in transcribed

Figure 6 Rules Menu Item

image text in transcribed

Figure 7 Exit Menu Item

image text in transcribed

Figure 8 Project View

Edit provided-

Game.Java:

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package core; import java.awt.Color; import java.util.ArrayList; import constants.constants; public final class Game implements IGame { private int attempt; private Codebreaker codebreaker; private Codemaker codemaker; public Game() { // instantiate the instances of the member variables codemaker = new Codemaker(); codebreaker = new Codebreaker() { @Override public void checkCode(ArrayList attempt) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }; attempt = 0; play(); } public void play() { while(true){ // will loop again and again until codebreaker wins or runs out of attempts if(attempt codeBreakerAttempt=codebreaker.getCodebreakerAttempt(); codemaker.checkAttemptedCode(codeBreakerAttempt); boolean win=codebreaker.CheckCode(codemaker.getCodemakerResponse()); /*checkCode function of ICodebreaker has been modified,will return true if codebreaker wins*/ if(win){ System.out.println("Codebreaker wins"); break; //breaking the loop } }else{ System.out.println("Codemaker wins"); //after max attempts and codebreaker couldn't guess correctly break; } attempt++; } } /** * @return the attempt */ public int getAttempt() { return attempt; } /** * @param attempt the attempt to set */ public void setAttempt(int attempt) { this.attempt = attempt; } /** * @return the codebreaker */ public Codebreaker getCodebreaker() { return codebreaker; } /** * @param codebreaker the codebreaker to set */ public void setCodebreaker(Codebreaker codebreaker) { this.codebreaker = codebreaker; } /** * @return the codemaker */ public Codemaker getCodemaker() { return codemaker; } /** * @param codemaker the codemaker to set */ public void setCodemaker(Codemaker codemaker) { this.codemaker = codemaker; } public void checkIfWon(){ } } 

Codemaker:

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package core; import constants.constants; import java.awt.Color; import java.util.ArrayList; import java.util.HashSet; import java.util.Random; import java.util.Set; public final class Codemaker implements ICodemaker { // member variables private Set secretCode; private ArrayList codemakerResponse; public Codemaker() { // instantiate the member variable objects secretCode = new HashSet(); codemakerResponse = new ArrayList(); // call the method to generate the secret code generateSecretCode(); } public void generateSecretCode() { Random random = new Random(); //randomly select four of the eight colors to be the secret code, only // use each color once while(secretCode.size()  { System.out.println(color.toString()); }); } /** * @return the secretCode */ public Set getSecretCode() { return secretCode; } /** * @param secretCode the secretCode to set */ public void setSecretCode(Set secretCode) { this.secretCode = secretCode; } /** * @return the codemakerResponse */ public ArrayList getCodemakerResponse() { return codemakerResponse; } /** * @param codemakerResponse the codemakerResponse to set */ public void setCodemakerResponse(ArrayList codemakerResponse) { this.codemakerResponse = codemakerResponse; } public void checkAttemptedCode(ArrayList attempt) { codemakerResponse.clear(); //resetting the response System.out.println("Codemaker is checking codebreaker attempt"); ArrayList evaluatedPos=new ArrayList(); //List for storing indices of right guesses ArrayList whitePegs=new ArrayList(); //A temporary list for storing indices of matching colors, with wrong positions int red_pegs=0,white_pegs=0; ArrayList secret=new ArrayList(); secret.addAll(getSecretCode()); if(secret.equals(attempt)){ red_pegs=4; white_pegs=0; for(int i=0;i 

Codebreaker:

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package core; import java.awt.Color; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Scanner; import constants.constants; public abstract class Codebreaker implements ICodebreaker { // member variables private ArrayList codebreakerAttempt; public Codebreaker() { // instanatiate the member variables codebreakerAttempt = new ArrayList(); } /** * @return the codebreakerAttempt */ public ArrayList getCodebreakerAttempt() { consoleAttempt(); return codebreakerAttempt; } /** * @param codebreakerAttempt the codebreakerAttempt to set */ public void setCodebreakerAttempt(ArrayList codebreakerAttempt) { this.codebreakerAttempt = codebreakerAttempt; } /** * * @param attempt * @return */ public boolean CheckCode(ArrayList attempt) { boolean errorFlag=false; for (Color color : attempt) { if(color!=Color.RED){ //only if ALL the colors in the list are red, attempt is correct else wrong / partially correct errorFlag=true; } } if(errorFlag){ System.out.println("Found correct color in right position!"); System.out.println("Red pegs"); for (int i=0;i { System.out.print(" "+col); }); System.out.println(); } else{ consoleAttempt(); } } private Color stringToColor(String colorString){ Color color; try{ Field field=Class.forName("java.awt.Color").getField(colorString); color=(Color)field.get(null); }catch (Exception e) { color=null; } return color; } } 

Check Check

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

Climate And Environmental Database Systems

Authors: Michael Lautenschlager ,Manfred Reinke

1st Edition

1461368332, 978-1461368335

More Books

Students also viewed these Databases questions