Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program in java. The use of classes are not allowed since we have not le

ID: 3790082 • Letter: W

Question

Write a program in java.

The use of classes are not allowed since we have not learned that yet and this is the very beggining of java within the first week of class.

Write the game high low using a 1d array . What I am trying to accomplish is to basically load the array with random numbers and allow the user to see the first element in the array. After this the user will guess if the next number in the array will be higher or lower then the number show. If they guess correctly then they earn a point and we move onto the next position in the array where they will guess again high or low. This will continue until they are out of spots in the array and the game will be over. It the end it will display the total number of correct guesses and wrong guesses.

This is what I have and unforunately am pretty lost. Please help

package memory;

import java.util.Scanner;

import java.util.Random;

public class memoryGame {

public static void main(String[] args) {

   Random rand = new Random();

   int[] array;  

   array = new int[13];

   int guess;

  

   // Loading the array with random numbers

  

   for(int i= 0; i <array.length; i++){

       int randomNumbers = rand.nextInt(13);

       array[i] = randomNumbers;

       }

  

   while (true){

   System.out.println(" High Low ");

   System.out.println("------------------------------- ");

   System.out.println("Your first number is "+array[0]);

   System.out.println("Is the next number Higher or Lower (1 higher , 2 Lower) ?");

   Scanner input = new Scanner(System.in);

   guess = input.nextInt();

  

     

   if (array[0]< array[1]){

       System.out.println("correct");  

   } else {

       System.out.println("Wrong");  

   }

  

   }

   }// end of main

}// end of memory game class

Explanation / Answer

Hi

I have modified the code and highlighted the code changes below

memoryGame.java

import java.util.Scanner;
import java.util.Random;
public class memoryGame {
public static void main(String[] args) {
Random rand = new Random();
int[] array;
array = new int[13];
int guess;
  
// Loading the array with random numbers
  
for(int i= 0; i <array.length; i++){
int randomNumbers = rand.nextInt(13);
array[i] = randomNumbers;
}
int correct = 0;
int wrong = 0;
int i= 0;
while (i < array.length-1){
int flag = 1;
System.out.println(" High Low ");
System.out.println("------------------------------- ");
System.out.println("Your number is "+array[i]);
System.out.println("Is the next number Higher or Lower (1 higher , 2 Lower) ?");
Scanner input = new Scanner(System.in);
guess = input.nextInt();
  

if (array[i]< array[i+1]){
System.out.println("correct");
flag = 1;
} else {
System.out.println("Wrong");
flag = 2;
}
if(flag == guess){
   correct++;
}
else{
   wrong++;
}
i++;
}
System.out.println("The total number of correct guesses "+correct);
System.out.println("The total number of wrong guesses "+wrong);
  
}// end of main
}// end of memory game class

Output:

   High Low
-------------------------------
Your number is 4
Is the next number Higher or Lower (1 higher , 2 Lower) ?
1
correct
   High Low
-------------------------------
Your number is 6
Is the next number Higher or Lower (1 higher , 2 Lower) ?
1
correct
   High Low
-------------------------------
Your number is 12
Is the next number Higher or Lower (1 higher , 2 Lower) ?
1
Wrong
   High Low
-------------------------------
Your number is 12
Is the next number Higher or Lower (1 higher , 2 Lower) ?
1
Wrong
   High Low
-------------------------------
Your number is 7
Is the next number Higher or Lower (1 higher , 2 Lower) ?
1
correct
   High Low
-------------------------------
Your number is 10
Is the next number Higher or Lower (1 higher , 2 Lower) ?
1
correct
   High Low
-------------------------------
Your number is 12
Is the next number Higher or Lower (1 higher , 2 Lower) ?
1
Wrong
   High Low
-------------------------------
Your number is 5
Is the next number Higher or Lower (1 higher , 2 Lower) ?
1
Wrong
   High Low
-------------------------------
Your number is 5
Is the next number Higher or Lower (1 higher , 2 Lower) ?
1
correct
   High Low
-------------------------------
Your number is 8
Is the next number Higher or Lower (1 higher , 2 Lower) ?
1
Wrong
   High Low
-------------------------------
Your number is 5
Is the next number Higher or Lower (1 higher , 2 Lower) ?
1
correct
   High Low
-------------------------------
Your number is 11
Is the next number Higher or Lower (1 higher , 2 Lower) ?
1
Wrong
The total number of correct guesses 6
The total number of wrong guesses 6

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote