これは、画面上で最大 3 つの数字が点滅し、数秒間消えてからユーザーに数字を再生するように求める記憶実験です。ユーザーの回答の精度を計算するために配列を使用しようとしています。そのため、どの数値がどこにあるかを知るために、ランダムジェネレーターメソッドで2次元配列を使用しようとしていました. かなり非効率かもしれませんが、頑張っています。これが私がこれまでに持っているものです...
import java.util.*;
public class Pitt3
{
static int pause = 4;
static int Screen_Size = 100;
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
//USED TO CALC. USER'S ACCURACY
int accuracy = 99;
for (int x = 0; x<2; x++)
{
//CREATES ARRAYS TO GENERATE DIGITS
int[] array1 = new int[generateDigits(1)];
int[] array2 = new int[generateDigits(1)];
int[] array3 = new int[generateDigits(1)];
//PRINTS OUT #'S + PAUSES
System.out.println("Here are your numbers: ");
System.out.println(generateDigits(1));
System.out.println(generateDigits(1));
System.out.println(generateDigits(1)); pause(4);
//SPACES OUT THE QUESTION FROM ANSWER
System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" +
"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" +
"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
//PRINTS OUT #'S + PAUSES
System.out.println("What is the first number? ");
int ANSWER1a = keyboard.nextInt();
System.out.println("What is the second number? ");
int ANSWER1b = keyboard.nextInt();
System.out.println("What is the third number? ");
int ANSWER1c = keyboard.nextInt();
if (ANSWER1a != array1[0] || ANSWER1b != array2[0] || ANSWER1c != array3[0])
{
accuracy = (accuracy - 33);
}
if (ANSWER1a == array1[0] || ANSWER1b == array2[0] || ANSWER1c == array3[0])
{
accuracy = accuracy;
}
System.out.println("Your accuracy was " + accuracy + "%");
}
}
/**
*GENERATES A RANDOM #
*/
public static int generateDigits(int maxDigits)
{
Random generator = new Random();
int numberDigits = generator.nextInt(maxDigits) + 1;
int result = 0;
for(int n = 0; n < numberDigits; n++)
{
result = result + generator.nextInt(10);
}
return result;
}
/**
*SETS COMP. TO SLEEP FOR SPECIFIED SECONDS
*/
public static int pause (int seconds)
{
try
{
Thread.sleep(seconds * 1000);
}
catch (InterruptedException e){}
return pause;
}
}