SlideShare a Scribd company logo
Exercise 1 (10 Points): Define a FixdLenStringList class that encapsulate a list of strings and a
string length. All string in a FixdLenStringList have the same length. There is not limit on
number of strings (dynamic array) that a FixdLenStringList can hold. For example, The
FixdLenStringList list1 may contain the strings aa, bb, cc, and dd (all strings of length 2). The
FixdLenStringList list2 may contain the strings cat, dog, pig, fox, bat, and eel (all strings of
length 3). An incomplete implementation of the FixdLenStringList.java class is provided with
this exercise: Here are the required methods in the FixdLenStringList class that you need to
implement. i) Public constructor – This constructor will have one parameter that will indicate the
length of each string in FixdLenStringList’s list. The constructor will initialize strLength with
this value and will initialize FixdLenStringList’s list of strings, possibleStrings, to have 0 entries.
ii) You are to implement the found method. This method returns true if its String parameter key
is found in the list of strings, false otherwise. iii) You are to implement the addString method.
This method will add a string to the FixdLenStringList’s list if it is the correct length and not
already in the list. If the string is already in the list or if the string is not the correct length, it is
not added. HINT: you may call method found that is specified in part ii of this problem. iv) You
are to implement the method removeRandomString that will remove and return a random string
entry from FixdLenStringList’s list of strings. Write a client test class for testing the
FixdLenStringList class. Supply, your client class along with screen shots of some test runs.
Exercise 2: [20 Points] In this exercise, we will create a memory game called “Mind Game”. In
this game, even number of tiles are placed face-down in rows on a “Mind Game Board”. Each
tile contains an image. For each tile, there is exactly one other tile with the same image. The
player is to pick a tile, see which image it has, and try to find its match from the remaining face-
down tiles. If the player fails to turn over its match, both tiles are turned face-down and the
player attempts to pick a matching pair again. The game is over when all tiles on the board are
turned face-up. In this implementation of a simplified version of Mind Game, • Images will be
strings chosen from a FixdLenStringList. (Use the FixdLenStringList class from exercise 1). •
The mind game board will contain even number of Tiles. • The board will be implemented as a
one-dimensional array of Tiles. For example, if the size of the mind game board is requested to
be 4, then the board will have 16 tiles. The one dimension array, gameBoard, can be viewed as a
4-by-4 mind game board as follows: gameBoard[0] gameBoard[1] gameBoard[2] gameBoard[3]
gameBoard[4] gameBoard[5] gameBoard[6] gameBoard[7] gameBoard[8] gameBoard[9]
gameBoard[10] gameBoard[11] gameBoard[12] gameBoard[13] gameBoard[14] gameBoard[15]
An incomplete implementation of the Tile and Board classes are provided with this exercise
(Tile.java, Board.java). You should examine these classes and complete them with the following
methods. To implement the methods, see the specifications provided in the comments of the
methods. a) Write the implementation of the Board method fillBoard, which will randomly fill
the mind game board with Tiles whose images (strings) are randomly chosen from the strings
contained in the FixdLenStringList. A tile image that appears on the board appears exactly twice
on the board. b) Write the implementation for the Board method lookAtTile. This method will
call the appropriate method of the Tile class to turn the Tile face-up. c) Write the implementation
for the Board’s method checkMatch. This method will check whether the tiles in its two integer
parameter positions on gameBoard have the same image. If they do, the tiles will remain face-up.
If they have different images, then tiles will be turned face-down. (See the comments that were
given in the problem specification). d) Complete the implementation for printBoard so that the
Mind Game board is printed as described in the comment. For example, you should call the
Board method format to right-justify the printing of the Tile image or the printing of the Tile
position. An example of printBoard for a 4 by 4 mind game board that is partially solved is
shown below after 4 matches have been found. The FixdLenStringList passed as a parameter to
Board constructor contains strings of length 3. fox fox dog dog cow 5 6 7 cow cat 10 11 12 13 14
15 Write a MindGame.java class that will handle user input and simulate the mind game to the
user. An example run of the mind Game is provided below: 0 1 2 3 Choose positions:1 2 pig , cat
0 1 2 3 Choose positions:0 1 cat , pig 0 1 2 3 Choose positions:0 3 cat , pig 0 1 2 3 Choose
positions:1 3 pig , pig 0 pig 2 pig Choose positions:0 2 cat , cat cat pig cat pig
import java.util.ArrayList;
import java.util.Collections;
/**
* The mind game board containing n by n tiles.
*
* @author musfiqrahman
*/
public class Board {
private Tile[] gameBoard; // Mind Game board of Tiles
private int size; // Number of Tiles on board
private int rowLength; // Number of Tiles printed in a row
private int numberOfTileFaceUp; // Number of Tiles face-up
private FixdLenStringList possibleTileValues; // Possible Tile values
/**
* Constructs n by n mind game board of Tiles whose image values are chosen
* from the already filled FixdLenStringList. Precondition: n is the length
* of a side of the board, n is an even positive integer. FixdLenStringList
* contains at least n * n / 2 strings.
*
* @param n is length of the side of the mind game board (an even number)
* @param list the FixdLenStringList from which the values for the tiles are
* chosen
*/
public Board(int n, FixdLenStringList list) {
// your code goes here
}
/**
* Randomly fills this Mind Game Board with tiles. The number of distinct
* tiles used on the board is size/2. Any one tile image appears exactly
* twice. Precondition: number of position on board is even,
* FixdLenStringList contains at least size / 2 elements.
*/
private void fillBoard() {
// Your code goes here
// You may find Collections.shuffle() class useful.
}
/**
* Precondition: 0 <= p < gameBoard.length. Precondition: Tile in position p
* is face-down. Postcondition: After execution, Tile in position p is
* face-up @param p the index of the tile to turn face-up
*/
public void lookAtTile(int p) {
// Your code goes here
}
/**
* Checks whether the Tiles in pos1 and pos2 have the same image. If they
* do, the Tiles are turned face-up. If not, the Tiles are turned face-down.
* Precondition: gameBoard[pos1] is face-up, gameBoard[pos2] is face-up
*
* @param pos1 index in gameBoard, 0 <= pos1 < gameBoard. length @param pos2
* index in gameBoard, 0 <= pos1 < gameBoard. length
*/
public void checkMatch(int pos1, int pos2) {
// Your code goes here
}
/**
* Board is printed for the Player. If the Tile is turned face-up, the image
* is printed. If the Tile is turned face-down, the Tile position is
* printed.
*/
public void printBoard() {
final int PADDING = 3;
int spacing = possibleTileValues.getStringLength() + PADDING;
for (int i = 0; i < size; i++) {
// Your code goes here
}
}
/**
* Returns Tile in position pos. Precondition: 0 <= pos < gameBoard.length.
* @param pos
*
* is index in gameBoard
* @return tile in position pos, null otherwise
*/
public Tile pickTile(int pos) {
if (pos < 0 || pos >= gameBoard.length) {
return null;
}
return gameBoard[pos];
}
/**
* Right-justifies a number to a given number of places.
*
* @param number an integer to be formatted
* @param p total number of characters in returned string
* @return right-justified number with p places as a string
*/
private String format(int number, int p) {
String str = String.format("%1$" + p + "s", (number + ""));
return str;
}
/**
* Right-justifies a string to a given number of places.
*
* @param word a string to be formatted
* @param p total number of characters in returned string
* @return right-justified word with p places as a string
*/
private String format(String word, int p) {
String str = String.format("%1$" + p + "s", word);
return str;
}
/**
* Checks whether all tiles are face-up.
*
* @return true if all tiles are face-up; false otherwise
*/
public boolean allTilesUp() {
// Your code goes here
}
}
import java.util.Scanner;
/**
* This client class play starts the mind game and controls user input.
*/
public class MindGameClient {
public static void main(String[] args) {
FixdLenStringList fl = new FixdLenStringList(3);
fl.addString("cat");
fl.addString("dog");
fl.addString("pig");
fl.addString("eel");
fl.addString("pet");
fl.addString("net");
fl.addString("ted");
fl.addString("car");
Board b = new Board(4, fl);
b.printBoard();
Scanner kb = new Scanner(System.in);
while (!b.allTilesUp()) {
System.out.print("Choose positions:");
int n1 = kb.nextInt();
int n2 = kb.nextInt();
if (b.pickTile(n1) != null && b.pickTile(n2) != null) {
System.out.print(b.pickTile(n1).getImage() + " , ");
System.out.println(b.pickTile(n2).getImage());
System.out.println("");
b.checkMatch(n1, n2);
b.printBoard();
} else {
System.out.println("Invalid Selection!");
}
}
}
}
/**
* Tile for the Mind Game. A tile has an image and cabe be placed either
* face-up or face-down.
*/
public class Tile {
private String image;
private boolean faceUP;
/**
* Constructor for the Tile class. initially, face-down.
*
* @param word a tile is created with the string word
*/
public Tile(String word) {
// Your code goes here
}
/**
* Shows image on face-up Tile
*
* @return image if Tile is face-up; otherwise returns the empty string
*/
public String showFace() {
// Your code goes here
}
/**
* Checks whether Tile is face-up.
*
* @return true if Tile is face-up; false otherwise
*/
public boolean isFaceUp() {
// Your code goes here
}
/**
* Getter method for image
*
* @return the image string.
*/
public String getImage() {
return image;
}
/**
* Compares images on Tiles
*
* @param other image to be compared to image on this tile
* @return true if the image on other is the same as this image; false
* otherwise
*/
@Override
public boolean equals(Object other) {
// Your code goes here
// self check
// null check
// type check and cast
// field comparison
}
/**
* Turns Tile face-up Precondition: Tile is turned face-up
*/
public void turnFaceUp() {
// Your code goes here
}
/**
* Turns Tile face-down Precondition: Tile is turned face-down
*/
public void turnFaceDown() {
// Your code goes here
}
}
import java.util.ArrayList;
import java.util.Random;
/**
* FixdLenStringList defines a list of strings and a string length. All
* strings in the FixdLenStringList have the same length. There is no
* present number of strings that a FixdLenStringList can hold.
*/
public class FixdLenStringList {
private final int strLength;
private ArrayList availableStrings;
/**
* Constructor for FixedLenStringList that initializes strLength ( the
* length of the strings in FixdLenStringList's list) and possibleStrings
* (FixdLenStringList's list of strings).
*
* @param len the length of the FixdLenStringList's strings.
*/
public FixdLenStringList(int len) {
strLength = len;
availableStrings = new ArrayList();
}
/**
* Gets the length of a string in FixdLenStringList
*
* @return length of the individual the strings in FixdLenStringList
*/
public int getStringLength() {
// Your code goes here
}
/**
* Returns the string in position x of FixdLenStringList's list
* implementation. The first string is in position 0. Precondition: 0 <= x <
* availableStrings.length @param x an index
*
* value in the FixdLenStringList
* @return returns the xth entry in FixdLenStringList
*/
public String getString(int x) {
// Your code goes here
}
/**
* Returns true if the string, key, is found in the FixdLenStringList's list
* of strings, false otherwise.
*
* @param key the string we are searching for
* @return true if key is found in FixdLenStringList; false otherwise
*/
public boolean found(String key) {
// Your code goes here
}
/**
* Adds the string, entry, to FixdLenStringList's list implementation if it
* is the correct length and not already in the list. If the string is
* already in the list or if the string is not the correct length, it is not
* added.
*
* @param entry string to add to FixdLenStringList
*/
public void addString(String entry) {
// Your code goes here
}
/**
* Removes and returns a random string entry from the FixdLenStringList's
* list of strings. Precondition: the FixdLenStringList's list must not be
* empty.
*
* @return a random string from FixdLenStringList
*/
public String removeRandomString() {
// Your code goes here
}
}
12 13 14 15
An example run of the mind Game is provided below:
01
23
Choose positions:1 2
pig , cat
01
23
Choose positions:0 1
cat , pig
01
23
Choose positions:0 3
cat , pig
01
23
Choose positions:1 3
pig , pig
0 pig
cat , cat
Solution
Exercise1:
import java.util.ArrayList;
import java.util.Random;
/**
* FixdLenStringList defines a list of strings and a string length. All
* strings in the FixdLenStringList have the same length. There is no
* present number of strings that a FixdLenStringList can hold.
*/
public class FixdLenStringList {
private final int strLength;
private ArrayList availableStrings;
/**
* Constructor for FixedLenStringList that initializes strLength ( the
* length of the strings in FixdLenStringList's list) and possibleStrings
* (FixdLenStringList's list of strings).
*
* @param len the length of the FixdLenStringList's strings.
*/
public FixdLenStringList(int len) {
strLength = len;
availableStrings = new ArrayList();
}
/**
* Gets the length of a string in FixdLenStringList
*
* @return length of the individual the strings in FixdLenStringList
*/
public int getStringLength() {
return strLength;
}
/**
* Returns the string in position x of FixdLenStringList's list
* implementation. The first string is in position 0. Precondition: 0 <= x <
* availableStrings.length @param x an index
*
* value in the FixdLenStringList
* @return returns the xth entry in FixdLenStringList
*/
public String getString(int x) {
if(0<=x && x

More Related Content

Similar to Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdf

The Ring programming language version 1.5.3 book - Part 48 of 184
The Ring programming language version 1.5.3 book - Part 48 of 184The Ring programming language version 1.5.3 book - Part 48 of 184
The Ring programming language version 1.5.3 book - Part 48 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 58 of 184
The Ring programming language version 1.5.3 book - Part 58 of 184The Ring programming language version 1.5.3 book - Part 58 of 184
The Ring programming language version 1.5.3 book - Part 58 of 184Mahmoud Samir Fayed
 
Inheritance - Creating a Multilevel Hierarchy In this lab- you will s.pdf
Inheritance - Creating a Multilevel Hierarchy  In this lab- you will s.pdfInheritance - Creating a Multilevel Hierarchy  In this lab- you will s.pdf
Inheritance - Creating a Multilevel Hierarchy In this lab- you will s.pdfEvanpZjSandersony
 
Inheritance - Creating a Multilevel Hierarchy In this lab- you will s.pdf
Inheritance - Creating a Multilevel Hierarchy  In this lab- you will s.pdfInheritance - Creating a Multilevel Hierarchy  In this lab- you will s.pdf
Inheritance - Creating a Multilevel Hierarchy In this lab- you will s.pdfvishalateen
 
R Markdown Reference Guide for reproducible research
R Markdown Reference Guide for reproducible researchR Markdown Reference Guide for reproducible research
R Markdown Reference Guide for reproducible researchdanxexcel
 
#include iostream#include fstream#include Opening.h.docx
#include iostream#include fstream#include Opening.h.docx#include iostream#include fstream#include Opening.h.docx
#include iostream#include fstream#include Opening.h.docxadkinspaige22
 
The Ring programming language version 1.4 book - Part 14 of 30
The Ring programming language version 1.4 book - Part 14 of 30The Ring programming language version 1.4 book - Part 14 of 30
The Ring programming language version 1.4 book - Part 14 of 30Mahmoud Samir Fayed
 
You will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdfYou will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdfFashionColZone
 
#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdfaquacareser
 
#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdfaquapariwar
 
Connect4.c2. Include the string.h header file3. Declare the foll.pdf
Connect4.c2. Include the string.h header file3. Declare the foll.pdfConnect4.c2. Include the string.h header file3. Declare the foll.pdf
Connect4.c2. Include the string.h header file3. Declare the foll.pdfshakilaghani
 
Please help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdfPlease help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdfmanjan6
 
Artificial intelligence - python
Artificial intelligence - pythonArtificial intelligence - python
Artificial intelligence - pythonSunjid Hasan
 
The Morse code (see Table 6.10 in book) is a common code that is use.pdf
The Morse code (see Table 6.10 in book) is a common code that is use.pdfThe Morse code (see Table 6.10 in book) is a common code that is use.pdf
The Morse code (see Table 6.10 in book) is a common code that is use.pdfbhim1213
 
Create a Java non-GUI stand-alone application that displays a histog
Create a Java non-GUI stand-alone application that displays a histogCreate a Java non-GUI stand-alone application that displays a histog
Create a Java non-GUI stand-alone application that displays a histogkedsliemichal
 
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...Yashpatel821746
 
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...Yashpatel821746
 

Similar to Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdf (20)

The Ring programming language version 1.5.3 book - Part 48 of 184
The Ring programming language version 1.5.3 book - Part 48 of 184The Ring programming language version 1.5.3 book - Part 48 of 184
The Ring programming language version 1.5.3 book - Part 48 of 184
 
The Ring programming language version 1.5.3 book - Part 58 of 184
The Ring programming language version 1.5.3 book - Part 58 of 184The Ring programming language version 1.5.3 book - Part 58 of 184
The Ring programming language version 1.5.3 book - Part 58 of 184
 
Shoot-for-A-Star
Shoot-for-A-StarShoot-for-A-Star
Shoot-for-A-Star
 
Inheritance - Creating a Multilevel Hierarchy In this lab- you will s.pdf
Inheritance - Creating a Multilevel Hierarchy  In this lab- you will s.pdfInheritance - Creating a Multilevel Hierarchy  In this lab- you will s.pdf
Inheritance - Creating a Multilevel Hierarchy In this lab- you will s.pdf
 
Inheritance - Creating a Multilevel Hierarchy In this lab- you will s.pdf
Inheritance - Creating a Multilevel Hierarchy  In this lab- you will s.pdfInheritance - Creating a Multilevel Hierarchy  In this lab- you will s.pdf
Inheritance - Creating a Multilevel Hierarchy In this lab- you will s.pdf
 
R Markdown Reference Guide for reproducible research
R Markdown Reference Guide for reproducible researchR Markdown Reference Guide for reproducible research
R Markdown Reference Guide for reproducible research
 
Java Unit 1 Project
Java Unit 1 ProjectJava Unit 1 Project
Java Unit 1 Project
 
#include iostream#include fstream#include Opening.h.docx
#include iostream#include fstream#include Opening.h.docx#include iostream#include fstream#include Opening.h.docx
#include iostream#include fstream#include Opening.h.docx
 
The Ring programming language version 1.4 book - Part 14 of 30
The Ring programming language version 1.4 book - Part 14 of 30The Ring programming language version 1.4 book - Part 14 of 30
The Ring programming language version 1.4 book - Part 14 of 30
 
You will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdfYou will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdf
 
Computer Network Assignment Help
Computer Network Assignment HelpComputer Network Assignment Help
Computer Network Assignment Help
 
#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf
 
#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf
 
Connect4.c2. Include the string.h header file3. Declare the foll.pdf
Connect4.c2. Include the string.h header file3. Declare the foll.pdfConnect4.c2. Include the string.h header file3. Declare the foll.pdf
Connect4.c2. Include the string.h header file3. Declare the foll.pdf
 
Please help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdfPlease help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdf
 
Artificial intelligence - python
Artificial intelligence - pythonArtificial intelligence - python
Artificial intelligence - python
 
The Morse code (see Table 6.10 in book) is a common code that is use.pdf
The Morse code (see Table 6.10 in book) is a common code that is use.pdfThe Morse code (see Table 6.10 in book) is a common code that is use.pdf
The Morse code (see Table 6.10 in book) is a common code that is use.pdf
 
Create a Java non-GUI stand-alone application that displays a histog
Create a Java non-GUI stand-alone application that displays a histogCreate a Java non-GUI stand-alone application that displays a histog
Create a Java non-GUI stand-alone application that displays a histog
 
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
 
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
 

More from fms12345

Describe the procedure you would use in the laboratory to determine .pdf
Describe the procedure you would use in the laboratory to determine .pdfDescribe the procedure you would use in the laboratory to determine .pdf
Describe the procedure you would use in the laboratory to determine .pdffms12345
 
CHEM 1011 Discussion question 2ObjectiveTo learn more about the .pdf
CHEM 1011 Discussion question 2ObjectiveTo learn more about the .pdfCHEM 1011 Discussion question 2ObjectiveTo learn more about the .pdf
CHEM 1011 Discussion question 2ObjectiveTo learn more about the .pdffms12345
 
Could you implement this please. I was told to use pointers as the d.pdf
Could you implement this please. I was told to use pointers as the d.pdfCould you implement this please. I was told to use pointers as the d.pdf
Could you implement this please. I was told to use pointers as the d.pdffms12345
 
A piece of malware is running on a Windows 7 machine via process inj.pdf
A piece of malware is running on a Windows 7 machine via process inj.pdfA piece of malware is running on a Windows 7 machine via process inj.pdf
A piece of malware is running on a Windows 7 machine via process inj.pdffms12345
 
Company names Aerial Drones Surveillance Inc. Your company descript.pdf
Company names Aerial Drones Surveillance Inc. Your company descript.pdfCompany names Aerial Drones Surveillance Inc. Your company descript.pdf
Company names Aerial Drones Surveillance Inc. Your company descript.pdffms12345
 
2. The Lorenz curve measures inequality in person income distribution.pdf
2. The Lorenz curve measures inequality in person income distribution.pdf2. The Lorenz curve measures inequality in person income distribution.pdf
2. The Lorenz curve measures inequality in person income distribution.pdffms12345
 
13 808 PM docs.google.com Covalent Bonding and lonic Bonding study.pdf
13 808 PM  docs.google.com Covalent Bonding and lonic Bonding study.pdf13 808 PM  docs.google.com Covalent Bonding and lonic Bonding study.pdf
13 808 PM docs.google.com Covalent Bonding and lonic Bonding study.pdffms12345
 
1.The shrimping industry needs female shrimp for production purposes.pdf
1.The shrimping industry needs female shrimp for production purposes.pdf1.The shrimping industry needs female shrimp for production purposes.pdf
1.The shrimping industry needs female shrimp for production purposes.pdffms12345
 
Who are the stakeholders in an income statement and whySolution.pdf
Who are the stakeholders in an income statement and whySolution.pdfWho are the stakeholders in an income statement and whySolution.pdf
Who are the stakeholders in an income statement and whySolution.pdffms12345
 
Which company maintains natural habitats while B allowing us to live .pdf
Which company maintains natural habitats while B allowing us to live .pdfWhich company maintains natural habitats while B allowing us to live .pdf
Which company maintains natural habitats while B allowing us to live .pdffms12345
 
When multiple strains of the same bacterial species are sequenced, w.pdf
When multiple strains of the same bacterial species are sequenced, w.pdfWhen multiple strains of the same bacterial species are sequenced, w.pdf
When multiple strains of the same bacterial species are sequenced, w.pdffms12345
 
What specialized cells line the inner cavity and move fluids through.pdf
What specialized cells line the inner cavity and move fluids through.pdfWhat specialized cells line the inner cavity and move fluids through.pdf
What specialized cells line the inner cavity and move fluids through.pdffms12345
 
What does the metaphor meaning for the Iron curtainSolutionIr.pdf
What does the metaphor meaning for the Iron curtainSolutionIr.pdfWhat does the metaphor meaning for the Iron curtainSolutionIr.pdf
What does the metaphor meaning for the Iron curtainSolutionIr.pdffms12345
 
What are the major developmental milestones between infancy and todd.pdf
What are the major developmental milestones between infancy and todd.pdfWhat are the major developmental milestones between infancy and todd.pdf
What are the major developmental milestones between infancy and todd.pdffms12345
 
Using the Web or another research tool, search for alternative means.pdf
Using the Web or another research tool, search for alternative means.pdfUsing the Web or another research tool, search for alternative means.pdf
Using the Web or another research tool, search for alternative means.pdffms12345
 
Using Array Approach, Linked List approach, and Delete Byte Approach.pdf
Using Array Approach, Linked List approach, and Delete Byte Approach.pdfUsing Array Approach, Linked List approach, and Delete Byte Approach.pdf
Using Array Approach, Linked List approach, and Delete Byte Approach.pdffms12345
 
TV Guide magazine ran a cover photo for a story emphasizing Oprah Wi.pdf
TV Guide magazine ran a cover photo for a story emphasizing Oprah Wi.pdfTV Guide magazine ran a cover photo for a story emphasizing Oprah Wi.pdf
TV Guide magazine ran a cover photo for a story emphasizing Oprah Wi.pdffms12345
 
Tim Tassopoulos, the chief operating officer for Chick-Fll-A applies .pdf
Tim Tassopoulos, the chief operating officer for Chick-Fll-A applies .pdfTim Tassopoulos, the chief operating officer for Chick-Fll-A applies .pdf
Tim Tassopoulos, the chief operating officer for Chick-Fll-A applies .pdffms12345
 
The Hydrolysis of the Hydrated Pb ion PboH (aq) + H200SolutionP.pdf
The Hydrolysis of the Hydrated Pb ion PboH (aq) + H200SolutionP.pdfThe Hydrolysis of the Hydrated Pb ion PboH (aq) + H200SolutionP.pdf
The Hydrolysis of the Hydrated Pb ion PboH (aq) + H200SolutionP.pdffms12345
 
1. CDOs are normally divided into tranches. Holders of this tranche .pdf
1. CDOs are normally divided into tranches. Holders of this tranche .pdf1. CDOs are normally divided into tranches. Holders of this tranche .pdf
1. CDOs are normally divided into tranches. Holders of this tranche .pdffms12345
 

More from fms12345 (20)

Describe the procedure you would use in the laboratory to determine .pdf
Describe the procedure you would use in the laboratory to determine .pdfDescribe the procedure you would use in the laboratory to determine .pdf
Describe the procedure you would use in the laboratory to determine .pdf
 
CHEM 1011 Discussion question 2ObjectiveTo learn more about the .pdf
CHEM 1011 Discussion question 2ObjectiveTo learn more about the .pdfCHEM 1011 Discussion question 2ObjectiveTo learn more about the .pdf
CHEM 1011 Discussion question 2ObjectiveTo learn more about the .pdf
 
Could you implement this please. I was told to use pointers as the d.pdf
Could you implement this please. I was told to use pointers as the d.pdfCould you implement this please. I was told to use pointers as the d.pdf
Could you implement this please. I was told to use pointers as the d.pdf
 
A piece of malware is running on a Windows 7 machine via process inj.pdf
A piece of malware is running on a Windows 7 machine via process inj.pdfA piece of malware is running on a Windows 7 machine via process inj.pdf
A piece of malware is running on a Windows 7 machine via process inj.pdf
 
Company names Aerial Drones Surveillance Inc. Your company descript.pdf
Company names Aerial Drones Surveillance Inc. Your company descript.pdfCompany names Aerial Drones Surveillance Inc. Your company descript.pdf
Company names Aerial Drones Surveillance Inc. Your company descript.pdf
 
2. The Lorenz curve measures inequality in person income distribution.pdf
2. The Lorenz curve measures inequality in person income distribution.pdf2. The Lorenz curve measures inequality in person income distribution.pdf
2. The Lorenz curve measures inequality in person income distribution.pdf
 
13 808 PM docs.google.com Covalent Bonding and lonic Bonding study.pdf
13 808 PM  docs.google.com Covalent Bonding and lonic Bonding study.pdf13 808 PM  docs.google.com Covalent Bonding and lonic Bonding study.pdf
13 808 PM docs.google.com Covalent Bonding and lonic Bonding study.pdf
 
1.The shrimping industry needs female shrimp for production purposes.pdf
1.The shrimping industry needs female shrimp for production purposes.pdf1.The shrimping industry needs female shrimp for production purposes.pdf
1.The shrimping industry needs female shrimp for production purposes.pdf
 
Who are the stakeholders in an income statement and whySolution.pdf
Who are the stakeholders in an income statement and whySolution.pdfWho are the stakeholders in an income statement and whySolution.pdf
Who are the stakeholders in an income statement and whySolution.pdf
 
Which company maintains natural habitats while B allowing us to live .pdf
Which company maintains natural habitats while B allowing us to live .pdfWhich company maintains natural habitats while B allowing us to live .pdf
Which company maintains natural habitats while B allowing us to live .pdf
 
When multiple strains of the same bacterial species are sequenced, w.pdf
When multiple strains of the same bacterial species are sequenced, w.pdfWhen multiple strains of the same bacterial species are sequenced, w.pdf
When multiple strains of the same bacterial species are sequenced, w.pdf
 
What specialized cells line the inner cavity and move fluids through.pdf
What specialized cells line the inner cavity and move fluids through.pdfWhat specialized cells line the inner cavity and move fluids through.pdf
What specialized cells line the inner cavity and move fluids through.pdf
 
What does the metaphor meaning for the Iron curtainSolutionIr.pdf
What does the metaphor meaning for the Iron curtainSolutionIr.pdfWhat does the metaphor meaning for the Iron curtainSolutionIr.pdf
What does the metaphor meaning for the Iron curtainSolutionIr.pdf
 
What are the major developmental milestones between infancy and todd.pdf
What are the major developmental milestones between infancy and todd.pdfWhat are the major developmental milestones between infancy and todd.pdf
What are the major developmental milestones between infancy and todd.pdf
 
Using the Web or another research tool, search for alternative means.pdf
Using the Web or another research tool, search for alternative means.pdfUsing the Web or another research tool, search for alternative means.pdf
Using the Web or another research tool, search for alternative means.pdf
 
Using Array Approach, Linked List approach, and Delete Byte Approach.pdf
Using Array Approach, Linked List approach, and Delete Byte Approach.pdfUsing Array Approach, Linked List approach, and Delete Byte Approach.pdf
Using Array Approach, Linked List approach, and Delete Byte Approach.pdf
 
TV Guide magazine ran a cover photo for a story emphasizing Oprah Wi.pdf
TV Guide magazine ran a cover photo for a story emphasizing Oprah Wi.pdfTV Guide magazine ran a cover photo for a story emphasizing Oprah Wi.pdf
TV Guide magazine ran a cover photo for a story emphasizing Oprah Wi.pdf
 
Tim Tassopoulos, the chief operating officer for Chick-Fll-A applies .pdf
Tim Tassopoulos, the chief operating officer for Chick-Fll-A applies .pdfTim Tassopoulos, the chief operating officer for Chick-Fll-A applies .pdf
Tim Tassopoulos, the chief operating officer for Chick-Fll-A applies .pdf
 
The Hydrolysis of the Hydrated Pb ion PboH (aq) + H200SolutionP.pdf
The Hydrolysis of the Hydrated Pb ion PboH (aq) + H200SolutionP.pdfThe Hydrolysis of the Hydrated Pb ion PboH (aq) + H200SolutionP.pdf
The Hydrolysis of the Hydrated Pb ion PboH (aq) + H200SolutionP.pdf
 
1. CDOs are normally divided into tranches. Holders of this tranche .pdf
1. CDOs are normally divided into tranches. Holders of this tranche .pdf1. CDOs are normally divided into tranches. Holders of this tranche .pdf
1. CDOs are normally divided into tranches. Holders of this tranche .pdf
 

Recently uploaded

MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxbennyroshan06
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxEduSkills OECD
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonSteve Thomason
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersPedroFerreira53928
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfQucHHunhnh
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfjoachimlavalley1
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345beazzy04
 
size separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticssize separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticspragatimahajan3
 
Gyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptxGyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptxShibin Azad
 
How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17Celine George
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasiemaillard
 
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxJose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxricssacare
 
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...Denish Jangid
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfbu07226
 
Salient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxSalient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxakshayaramakrishnan21
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasiemaillard
 
Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesRased Khan
 

Recently uploaded (20)

MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
Operations Management - Book1.p  - Dr. Abdulfatah A. SalemOperations Management - Book1.p  - Dr. Abdulfatah A. Salem
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
 
size separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticssize separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceutics
 
Gyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptxGyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptx
 
How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxJose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
 
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
Salient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxSalient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matrices
 

Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdf

  • 1. Exercise 1 (10 Points): Define a FixdLenStringList class that encapsulate a list of strings and a string length. All string in a FixdLenStringList have the same length. There is not limit on number of strings (dynamic array) that a FixdLenStringList can hold. For example, The FixdLenStringList list1 may contain the strings aa, bb, cc, and dd (all strings of length 2). The FixdLenStringList list2 may contain the strings cat, dog, pig, fox, bat, and eel (all strings of length 3). An incomplete implementation of the FixdLenStringList.java class is provided with this exercise: Here are the required methods in the FixdLenStringList class that you need to implement. i) Public constructor – This constructor will have one parameter that will indicate the length of each string in FixdLenStringList’s list. The constructor will initialize strLength with this value and will initialize FixdLenStringList’s list of strings, possibleStrings, to have 0 entries. ii) You are to implement the found method. This method returns true if its String parameter key is found in the list of strings, false otherwise. iii) You are to implement the addString method. This method will add a string to the FixdLenStringList’s list if it is the correct length and not already in the list. If the string is already in the list or if the string is not the correct length, it is not added. HINT: you may call method found that is specified in part ii of this problem. iv) You are to implement the method removeRandomString that will remove and return a random string entry from FixdLenStringList’s list of strings. Write a client test class for testing the FixdLenStringList class. Supply, your client class along with screen shots of some test runs. Exercise 2: [20 Points] In this exercise, we will create a memory game called “Mind Game”. In this game, even number of tiles are placed face-down in rows on a “Mind Game Board”. Each tile contains an image. For each tile, there is exactly one other tile with the same image. The player is to pick a tile, see which image it has, and try to find its match from the remaining face- down tiles. If the player fails to turn over its match, both tiles are turned face-down and the player attempts to pick a matching pair again. The game is over when all tiles on the board are turned face-up. In this implementation of a simplified version of Mind Game, • Images will be strings chosen from a FixdLenStringList. (Use the FixdLenStringList class from exercise 1). • The mind game board will contain even number of Tiles. • The board will be implemented as a one-dimensional array of Tiles. For example, if the size of the mind game board is requested to be 4, then the board will have 16 tiles. The one dimension array, gameBoard, can be viewed as a 4-by-4 mind game board as follows: gameBoard[0] gameBoard[1] gameBoard[2] gameBoard[3] gameBoard[4] gameBoard[5] gameBoard[6] gameBoard[7] gameBoard[8] gameBoard[9] gameBoard[10] gameBoard[11] gameBoard[12] gameBoard[13] gameBoard[14] gameBoard[15] An incomplete implementation of the Tile and Board classes are provided with this exercise (Tile.java, Board.java). You should examine these classes and complete them with the following methods. To implement the methods, see the specifications provided in the comments of the
  • 2. methods. a) Write the implementation of the Board method fillBoard, which will randomly fill the mind game board with Tiles whose images (strings) are randomly chosen from the strings contained in the FixdLenStringList. A tile image that appears on the board appears exactly twice on the board. b) Write the implementation for the Board method lookAtTile. This method will call the appropriate method of the Tile class to turn the Tile face-up. c) Write the implementation for the Board’s method checkMatch. This method will check whether the tiles in its two integer parameter positions on gameBoard have the same image. If they do, the tiles will remain face-up. If they have different images, then tiles will be turned face-down. (See the comments that were given in the problem specification). d) Complete the implementation for printBoard so that the Mind Game board is printed as described in the comment. For example, you should call the Board method format to right-justify the printing of the Tile image or the printing of the Tile position. An example of printBoard for a 4 by 4 mind game board that is partially solved is shown below after 4 matches have been found. The FixdLenStringList passed as a parameter to Board constructor contains strings of length 3. fox fox dog dog cow 5 6 7 cow cat 10 11 12 13 14 15 Write a MindGame.java class that will handle user input and simulate the mind game to the user. An example run of the mind Game is provided below: 0 1 2 3 Choose positions:1 2 pig , cat 0 1 2 3 Choose positions:0 1 cat , pig 0 1 2 3 Choose positions:0 3 cat , pig 0 1 2 3 Choose positions:1 3 pig , pig 0 pig 2 pig Choose positions:0 2 cat , cat cat pig cat pig import java.util.ArrayList; import java.util.Collections; /** * The mind game board containing n by n tiles. * * @author musfiqrahman */ public class Board { private Tile[] gameBoard; // Mind Game board of Tiles private int size; // Number of Tiles on board private int rowLength; // Number of Tiles printed in a row private int numberOfTileFaceUp; // Number of Tiles face-up private FixdLenStringList possibleTileValues; // Possible Tile values /** * Constructs n by n mind game board of Tiles whose image values are chosen * from the already filled FixdLenStringList. Precondition: n is the length * of a side of the board, n is an even positive integer. FixdLenStringList
  • 3. * contains at least n * n / 2 strings. * * @param n is length of the side of the mind game board (an even number) * @param list the FixdLenStringList from which the values for the tiles are * chosen */ public Board(int n, FixdLenStringList list) { // your code goes here } /** * Randomly fills this Mind Game Board with tiles. The number of distinct * tiles used on the board is size/2. Any one tile image appears exactly * twice. Precondition: number of position on board is even, * FixdLenStringList contains at least size / 2 elements. */ private void fillBoard() { // Your code goes here // You may find Collections.shuffle() class useful. } /** * Precondition: 0 <= p < gameBoard.length. Precondition: Tile in position p * is face-down. Postcondition: After execution, Tile in position p is * face-up @param p the index of the tile to turn face-up */ public void lookAtTile(int p) { // Your code goes here } /** * Checks whether the Tiles in pos1 and pos2 have the same image. If they * do, the Tiles are turned face-up. If not, the Tiles are turned face-down. * Precondition: gameBoard[pos1] is face-up, gameBoard[pos2] is face-up * * @param pos1 index in gameBoard, 0 <= pos1 < gameBoard. length @param pos2 * index in gameBoard, 0 <= pos1 < gameBoard. length */ public void checkMatch(int pos1, int pos2) {
  • 4. // Your code goes here } /** * Board is printed for the Player. If the Tile is turned face-up, the image * is printed. If the Tile is turned face-down, the Tile position is * printed. */ public void printBoard() { final int PADDING = 3; int spacing = possibleTileValues.getStringLength() + PADDING; for (int i = 0; i < size; i++) { // Your code goes here } } /** * Returns Tile in position pos. Precondition: 0 <= pos < gameBoard.length. * @param pos * * is index in gameBoard * @return tile in position pos, null otherwise */ public Tile pickTile(int pos) { if (pos < 0 || pos >= gameBoard.length) { return null; } return gameBoard[pos]; } /** * Right-justifies a number to a given number of places. * * @param number an integer to be formatted * @param p total number of characters in returned string * @return right-justified number with p places as a string */ private String format(int number, int p) { String str = String.format("%1$" + p + "s", (number + ""));
  • 5. return str; } /** * Right-justifies a string to a given number of places. * * @param word a string to be formatted * @param p total number of characters in returned string * @return right-justified word with p places as a string */ private String format(String word, int p) { String str = String.format("%1$" + p + "s", word); return str; } /** * Checks whether all tiles are face-up. * * @return true if all tiles are face-up; false otherwise */ public boolean allTilesUp() { // Your code goes here } } import java.util.Scanner; /** * This client class play starts the mind game and controls user input. */ public class MindGameClient { public static void main(String[] args) { FixdLenStringList fl = new FixdLenStringList(3); fl.addString("cat"); fl.addString("dog"); fl.addString("pig"); fl.addString("eel"); fl.addString("pet");
  • 6. fl.addString("net"); fl.addString("ted"); fl.addString("car"); Board b = new Board(4, fl); b.printBoard(); Scanner kb = new Scanner(System.in); while (!b.allTilesUp()) { System.out.print("Choose positions:"); int n1 = kb.nextInt(); int n2 = kb.nextInt(); if (b.pickTile(n1) != null && b.pickTile(n2) != null) { System.out.print(b.pickTile(n1).getImage() + " , "); System.out.println(b.pickTile(n2).getImage()); System.out.println(""); b.checkMatch(n1, n2); b.printBoard(); } else { System.out.println("Invalid Selection!"); } } } } /** * Tile for the Mind Game. A tile has an image and cabe be placed either * face-up or face-down. */ public class Tile { private String image; private boolean faceUP; /** * Constructor for the Tile class. initially, face-down. * * @param word a tile is created with the string word */
  • 7. public Tile(String word) { // Your code goes here } /** * Shows image on face-up Tile * * @return image if Tile is face-up; otherwise returns the empty string */ public String showFace() { // Your code goes here } /** * Checks whether Tile is face-up. * * @return true if Tile is face-up; false otherwise */ public boolean isFaceUp() { // Your code goes here } /** * Getter method for image * * @return the image string. */ public String getImage() { return image; } /** * Compares images on Tiles * * @param other image to be compared to image on this tile * @return true if the image on other is the same as this image; false * otherwise */ @Override public boolean equals(Object other) {
  • 8. // Your code goes here // self check // null check // type check and cast // field comparison } /** * Turns Tile face-up Precondition: Tile is turned face-up */ public void turnFaceUp() { // Your code goes here } /** * Turns Tile face-down Precondition: Tile is turned face-down */ public void turnFaceDown() { // Your code goes here } } import java.util.ArrayList; import java.util.Random; /** * FixdLenStringList defines a list of strings and a string length. All * strings in the FixdLenStringList have the same length. There is no * present number of strings that a FixdLenStringList can hold. */ public class FixdLenStringList { private final int strLength; private ArrayList availableStrings; /** * Constructor for FixedLenStringList that initializes strLength ( the
  • 9. * length of the strings in FixdLenStringList's list) and possibleStrings * (FixdLenStringList's list of strings). * * @param len the length of the FixdLenStringList's strings. */ public FixdLenStringList(int len) { strLength = len; availableStrings = new ArrayList(); } /** * Gets the length of a string in FixdLenStringList * * @return length of the individual the strings in FixdLenStringList */ public int getStringLength() { // Your code goes here } /** * Returns the string in position x of FixdLenStringList's list * implementation. The first string is in position 0. Precondition: 0 <= x < * availableStrings.length @param x an index * * value in the FixdLenStringList * @return returns the xth entry in FixdLenStringList */ public String getString(int x) { // Your code goes here } /** * Returns true if the string, key, is found in the FixdLenStringList's list * of strings, false otherwise. * * @param key the string we are searching for * @return true if key is found in FixdLenStringList; false otherwise */ public boolean found(String key) {
  • 10. // Your code goes here } /** * Adds the string, entry, to FixdLenStringList's list implementation if it * is the correct length and not already in the list. If the string is * already in the list or if the string is not the correct length, it is not * added. * * @param entry string to add to FixdLenStringList */ public void addString(String entry) { // Your code goes here } /** * Removes and returns a random string entry from the FixdLenStringList's * list of strings. Precondition: the FixdLenStringList's list must not be * empty. * * @return a random string from FixdLenStringList */ public String removeRandomString() { // Your code goes here } } 12 13 14 15 An example run of the mind Game is provided below: 01 23 Choose positions:1 2 pig , cat 01 23 Choose positions:0 1 cat , pig 01
  • 11. 23 Choose positions:0 3 cat , pig 01 23 Choose positions:1 3 pig , pig 0 pig cat , cat Solution Exercise1: import java.util.ArrayList; import java.util.Random; /** * FixdLenStringList defines a list of strings and a string length. All * strings in the FixdLenStringList have the same length. There is no * present number of strings that a FixdLenStringList can hold. */ public class FixdLenStringList { private final int strLength; private ArrayList availableStrings; /** * Constructor for FixedLenStringList that initializes strLength ( the * length of the strings in FixdLenStringList's list) and possibleStrings * (FixdLenStringList's list of strings). * * @param len the length of the FixdLenStringList's strings. */ public FixdLenStringList(int len) { strLength = len; availableStrings = new ArrayList(); } /**
  • 12. * Gets the length of a string in FixdLenStringList * * @return length of the individual the strings in FixdLenStringList */ public int getStringLength() { return strLength; } /** * Returns the string in position x of FixdLenStringList's list * implementation. The first string is in position 0. Precondition: 0 <= x < * availableStrings.length @param x an index * * value in the FixdLenStringList * @return returns the xth entry in FixdLenStringList */ public String getString(int x) { if(0<=x && x