Recently I was trying to build a simple computer game using java. Could someone
ID: 3839120 • Letter: R
Question
Recently I was trying to build a simple computer game using java. Could someone build a wordsearch game using java following the rubric bellow? The wordsearch would basically have a 2D array that would be 20 by 20 and each of the words inside the word search would be inside the 2D array the user is looking at. The 20 by 20 grid would be all stars to start with so * * * * like that but 20 by 20. The first question the program would ask would be "what coordinate would you like to check first" ( user answers) then it would repeat the question and the users goal would be to find the words by guessing the coordinates of the words.
The code needs to remain relatively simple but has no name requirements just make sure that the names of each of the three classes are able to reference each other when put into java. Thanks for the help.
Methods written but they are not used or called
6 (6%)
there are errors sending or returning data
4 (4%)
used to segment code to perform a function
2 (2%)
used to segment code to perform functions
0 (0%)
Only one main method
8 (8%)
Used 3+ classes and/or inheritance
6 (6%)
Used classes and/or inheritance once
4 (4%)
More than one class present but there are errors
2 (2%)
More than one class is present but not implemented
0 (0%)
One class used
8 (8%)
Arrays used and perform as designed
6 (6%)
Arrays used but a minor error
4 (4%)
Arrays used but major error
2 (2%)
Array exists but is not used
0 (0%)
No arrays in code
8 (8%)
Verbose comments
6 (6%)
Some descriptions
4 (4%)
Sparse comments
2 (2%)
Nonsense comments
0 (0%)
No comment or documentation
8 (8%)
Appropriate spacing/indent
6 (6%)
Some minor spacing issues
4 (4%)
Neglects spacing or indentation
2 (2%)
Difficult to follow code
0 (0%)
Impossible to follow code lines
8 (8%)
Loops, recursion and methods perform
6 (6%)
Loops, recursion and methods perform but no returns
4 (4%)
Fragmented code that performs no functionality
2 (2%)
Everything done in multiple lines of If-Else
0 (0%)
Repeated functions that could be in a method
8 (8%)
User feels comfortable using
6 (6%)
Minor guess work on what to do
4 (4%)
Troubling guess work on what to do
2 (2%)
Must look in code on how to interface
0 (0%)
Frustrating to use application
8 (8%)
Compiles without error
0 (0%)
0 (0%)
0 (0%)
0 (0%)
Does not compile or compile error
8 (8%)
Robust and tested well
0 (0%)
0 (0%)
0 (0%)
0 (0%)
Frail and crashes easily
8 (8%)
Yes
0 (0%)
0 (0%)
0 (0%)
0 (0%)
No
10 (10%)
Peer review Excellent
7 (7%)
Peer review Great
4 (4%)
Peer review Good
1 (1%)
Peer review Poor
0 (0%)
Peer review None
10 (10%)
Reviewed 3
6 (6%)
Reviewed 2
3 (3%)
Reviewed 1
0 (0%)
Reviewed 0
0 (0%)
Methods written but they are not used or called
Points:6 (6%)
there are errors sending or returning data
Points:4 (4%)
used to segment code to perform a function
Points:2 (2%)
used to segment code to perform functions
Points:0 (0%)
Only one main method
Classes Points:8 (8%)
Used 3+ classes and/or inheritance
Points:6 (6%)
Used classes and/or inheritance once
Points:4 (4%)
More than one class present but there are errors
Points:2 (2%)
More than one class is present but not implemented
Points:0 (0%)
One class used
Array Points:8 (8%)
Arrays used and perform as designed
Points:6 (6%)
Arrays used but a minor error
Points:4 (4%)
Arrays used but major error
Points:2 (2%)
Array exists but is not used
Points:0 (0%)
No arrays in code
Documented Points:8 (8%)
Verbose comments
Points:6 (6%)
Some descriptions
Points:4 (4%)
Sparse comments
Points:2 (2%)
Nonsense comments
Points:0 (0%)
No comment or documentation
Formatted Points:8 (8%)
Appropriate spacing/indent
Points:6 (6%)
Some minor spacing issues
Points:4 (4%)
Neglects spacing or indentation
Points:2 (2%)
Difficult to follow code
Points:0 (0%)
Impossible to follow code lines
Efficiency Points:8 (8%)
Loops, recursion and methods perform
Points:6 (6%)
Loops, recursion and methods perform but no returns
Points:4 (4%)
Fragmented code that performs no functionality
Points:2 (2%)
Everything done in multiple lines of If-Else
Points:0 (0%)
Repeated functions that could be in a method
User Friendliness Points:8 (8%)
User feels comfortable using
Points:6 (6%)
Minor guess work on what to do
Points:4 (4%)
Troubling guess work on what to do
Points:2 (2%)
Must look in code on how to interface
Points:0 (0%)
Frustrating to use application
Compile Error Points:8 (8%)
Compiles without error
Points:0 (0%)
Points:0 (0%)
Points:0 (0%)
Points:0 (0%)
Does not compile or compile error
Runtime Error Points:8 (8%)
Robust and tested well
Points:0 (0%)
Points:0 (0%)
Points:0 (0%)
Points:0 (0%)
Frail and crashes easily
Appropriate Content Points:8 (8%)
Yes
Points:0 (0%)
Points:0 (0%)
Points:0 (0%)
Points:0 (0%)
No
Peer Reviews Points:10 (10%)
Peer review Excellent
Points:7 (7%)
Peer review Great
Points:4 (4%)
Peer review Good
Points:1 (1%)
Peer review Poor
Points:0 (0%)
Peer review None
Peer Reviewer Points:10 (10%)
Reviewed 3
Points:6 (6%)
Reviewed 2
Points:3 (3%)
Reviewed 1
Points:0 (0%)
Reviewed 0
Points:0 (0%)
Explanation / Answer
PROGRAM CODE:
Things.java
package wordsearch;
/**
*
* Things class defines any thing
*
*/
public class Things {
String thing;
/**
* Initializes thing to *
*/
public Things() {
thing = "*";
}
/**
* initializes thing to thing
* @param thing
*/
public Things(String thing) {
this.thing = thing;
}
/**
* returns the thing
* @return thing
*/
public String getThing()
{
return thing;
}
}
Fruits.java
package wordsearch;
/**
* This class represents fruit thing
*
*/
public class Fruits extends Things{
/**
* List of fruits to feed into the things
*/
static String fruits[] = {"Mango", "Apple", "Orange", "Pears", "Strawberry", "Raspberry", "Grape",
"Banana", "Blackberry", "Blueberry", "Papaya", "Kiwi", "Apricot", "Jack fruit", "Pomegranate",
"Guava", "Melon", "Dragon fruit", "Pineapple","Peach"};
/**
* initializes fruit thing to *
*/
public Fruits() {
super();
}
/**
* initializes fruit thing to fruit
* @param fruit
*/
public Fruits(String fruit) {
super(fruit);
}
}
Drinks.java
package wordsearch;
/**
* This class represents Drink thing
*
*/
public class Drinks extends Things{
/**
* initializes drink thing to *
*/
public Drinks() {
super();
}
/**
* initializes drink thing to fruit
* @param drink
*/
public Drinks(String drink) {
super(drink);
}
/**
* List of drinks to feed into the things
*/
static String drinks[] = {"Milkshake", "Soda", "Water", "Hot chocolate", "Tea", "Coffee",
"Green Tea", "Juice", "Coke", "Lemonade", "Cocktail", "Moctail",
"Beer", "Red Wine", "White Wine", "Champagne", "Rum", "Cider", "Whiskey", "Brandy"};
}
WordSearch.java
package wordsearch;
import java.util.Random;
import java.util.Scanner;
/**
* Word Search class to play the word search game
*
*/
public class WordSearch {
/**
* scanner object to read the coordinates
* Two dimensional thing array which stores fruits and drink in 20X20 array
*/
static Scanner keyboard;
static Things things[][];
/**
* gets the coordinate values from user
* exits the program if the input is -1
* if the input is less than zero or greater than 19, asks the user to enter the coordinate again
* returns the valid coordinate
* @return valid input for the coordinate
*/
public static int getInt()
{
int value;
while(true)
{
value = keyboard.nextInt();
if(value == -1)
{
System.out.println("Thank you for playing!");
System.exit(0);
}
else if(value<0 || value >=20)
{
System.out.println("Enter a coordinate between 0 and 19");
continue;
}
else break;
}
return value;
}
/**
* Games plays here by showing the random selected word to the user and asking the user to
* guess the coordinates of the thing
* calls getInt() to read the input
* Prints the word at the inputed coordinate if it is wrong
* otherwise tells the user that they've guessed it right and starts playing again.
* @param thing
*/
public static void play(String thing)
{
System.out.println(" The word is " + thing);
while(true)
{
System.out.println("what coordinate would you like to check first (-1 to quit)? ");
int row = getInt();
int column = getInt();
if(things[row][column].getThing().equalsIgnoreCase(thing))
{
System.out.println("You guessed it right!");
}
else
{
System.out.println("Try again!");
System.out.println("You guessed " + things[row][column].getThing());
}
}
}
/**
* Initializes scanner and things objects and fills the things array with random values
* starts playing the game by calling play()
*/
public static void main(String[] args) {
keyboard = new Scanner(System.in);
things = new Things[20][20];
Random rand = new Random();
//filling up the array
for(int i=0; i<20; i++)
{
things[i] = new Things[20];
for(int j=0; j<10; j++)
{
things[i][j] = new Fruits(Fruits.fruits[rand.nextInt(20)]);
}
for(int j=10; j<20; j++)
{
things[i][j] = new Drinks(Drinks.drinks[rand.nextInt(20)]);
}
}
while(true)
{
int row = rand.nextInt(20);
int column = rand.nextInt(20);
play(things[row][column].getThing());
}
}
}
OUTPUT:
The word is Beer
what coordinate would you like to check first (-1 to quit)?
1 2
Try again!
You guessed Melon
what coordinate would you like to check first (-1 to quit)?
3 5
Try again!
You guessed Peach
what coordinate would you like to check first (-1 to quit)?
8 9
Try again!
You guessed Guava
what coordinate would you like to check first (-1 to quit)?
12 43
Enter a coordinate between 0 and 19
12 17
Try again!
You guessed Moctail
what coordinate would you like to check first (-1 to quit)?
-1
Thank you for playing!
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.