I need help with this assignment. I am a beginner programming with Java, and am
ID: 3762210 • Letter: I
Question
I need help with this assignment. I am a beginner programming with Java, and am not sure how to approach this.
Create a simple memory game using a single-dimension array.
Give the user a choice between difficult levels:
Easy – User gets 20 turns
Medium – User gets 10 turns
Hard – User gets 5 turns
When the user gets a match, they don't lose the turn.
If they don't get a match, they lose a turn. 5 incorrect guesses = game over.
The user guesses two items, these items are revealed to the user. If they match, the cards stay flipped over when presenting the puzzle. Otherwise re-hide the puzzle and ask for a new guess.
The user wins if they match all the items.
Create a game according to the above rules
Your array should use either numbers or letters. (integers might be easier)
You should have at least 10 items to match (so your array should be at least 20 items) If you do more than 10 items, you might want to give the player more turns.
The positions of the 10 items should be randomized every time the game is played. Note: populating the array is one of the big challenges of this assignment
After every guess "clear the screen" before outputting the puzzle again.
for (int n = 0; n < 10; n++)
System.out.println( " " );
Create a game according to the above rules
Your array should use either numbers or letters. (integers might be easier)
You should have at least 10 items to match (so your array should be at least 20 items) If you do more than 10 items, you might want to give the player more turns.
The positions of the 10 items should be randomized every time the game is played. Note: populating the array is one of the big challenges of this assignment
After every guess "clear the screen" before outputting the puzzle again.
Explanation / Answer
// Demonstrate a one-dimensional array.
class Array {
public static void main(String args[]) {
int month_days[];
month_days = new int[12];
month_days[0] = 31;
month_days[1] = 28;
month_days[2] = 31;
month_days[3] = 30;
month_days[4] = 31;
month_days[5] = 30;
month_days[6] = 31;
month_days[7] = 31;
month_days[8] = 30;
month_days[9] = 31;
month_days[10] = 30;
month_days[11] = 31;
System.out.println("April has " + month_days[3] + " days.");
}
}
// An improved version of the previous program.
class AutoArray {
public static void main(String args[]) {
int month_days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31,
30, 31 };
System.out.println("April has " + month_days[3] + " days.");
}
}
// Average an array of values.
fclass Average {
public static void main(String args[]) {
double nums[] = {10.1, 11.2, 12.3, 13.4, 14.5};
double result = 0;
int i;
for(i=0; i<5; i++)
result = result + nums[i];
System.out.println("Average is " + result / 5);
}
}
So this is how single dimention array uses in the program
as per your program
loop through this program for the choices of the level (hard, medium,..) - using for loop