Question

In: Computer Science

"Simon Says" is a memory game where "Simon" outputs a sequence of 10 characters (R, G, B, Y) and the user must repeat the sequence.

For Java

"Simon Says" is a memory game where "Simon" outputs a sequence of 10 characters (R, G, B, Y) and the user must repeat the sequence. Create a for loop that compares the two strings starting from index 0. For each match, add one point to userScore. Upon a mismatch, exit the loop using a break statement. Ex: The following patterns yield a userScore of 4: simonPattern: R, R, G, B, R, Y, Y, B, G, Y

import java.util.Scanner;

public class SimonSays {
   public static void main (String [] args) {
      String simonPattern = "";
      String userPattern = "";
      int userScore = 0;
      int i = 0;

      userScore = 0;
      simonPattern = "RRGBRYYBGY";
      userPattern = "RRGBBRYBGY";


      System.out.println("userScore: " + userScore);

      return;
   }
}

Solutions

Expert Solution

Program Screenshot:

import java.util.Scanner: public class SimonSays public static void main(String[ args) String simonPattern = ; String userP

Sample Output:

userScore: 4

Code to copy:

import java.util.Scanner;

public class SimonSays
{
   public static void main(String[] args)
   {
       String simonPattern = "";
       String userPattern = "";
       int userScore = 0;
       int i = 0;

       userScore = 0;
       simonPattern = "RRGBRYYBGY";
       userPattern = "RRGBBRYBGY";

       for (i = 0; i < simonPattern.length(); i++)
       {
           if (simonPattern.charAt(i) == userPattern.charAt(i))
           {
               userScore = userScore + 1;

           }
           else
           {
               break;
           }
       }
       System.out.println("userScore: " + userScore);
       return;
   }
}


Related Solutions

(C++) "Simon Says" is a memory game where "Simon" outputs a sequence of 10 characters (R, G, B, Y) and the user must repeat the sequence
(C++) "Simon Says" is a memory game where "Simon" outputs a sequence of 10 characters (R, G, B, Y) and the user must repeat the sequence. Create a for loop that compares the two strings starting from index 0. For each match, add one point to userScore. Upon a mismatch, exit the loop using a break statement. Assume simonPattern and userPattern are always the same length. Ex: The following patterns yield a userScore of 4: simonPattern: RRGBRYYBGY userPattern: RRGBBRYBGY
"Simon Says" is a memory game where "Simon" outputs a sequence of 10 characters (R, G,...
"Simon Says" is a memory game where "Simon" outputs a sequence of 10 characters (R, G, B, Y) and the user must repeat the sequence. Create a for loop that compares the two strings starting from index 0. For each match, add one point to userScore. Upon a mismatch, exit the loop using a break statement. Assume simonPattern and userPattern are always the same length. Ex: The following patterns yield a userScore of 4: simonPattern: RRGBRYYBGY userPattern: RRGBBRYBGY #include <stdio.h>...
"Simon Says" is a memory game where "Simon" outputs a sequence of 10 characters (R, G,...
"Simon Says" is a memory game where "Simon" outputs a sequence of 10 characters (R, G, B, Y) and the user must repeat the sequence. Create a for loop that compares the two strings starting from index 0. For each match, add one point to userScore. Upon a mismatch, exit the loop using a break statement. Ex: The following patterns yield a userScore of 4: simonPattern: RRGBRYYBGY userPattern: RRGBBRYBGY
Simon Says' is a memory game where 'Simon' outputs a sequence of 10 characters
Simon Says' is a memory game where 'Simon' outputs a sequence of 10 characters (R, G, B, Y) and the user must repeat the sequence. Create a for loop that compares the two strings starting from index 0. For each match, add one point to userScore. Upon a mismatch, exit the loop using a break statement. Ex: The following patterns yield a userScore of 4:simonPattern: R, R, G, B, R, Y, Y, B, G, YuserPattern:  R, R, G, B, B,...
Write a Java program that lets the user play a game where they must guess a...
Write a Java program that lets the user play a game where they must guess a number between zero and one hundred (0-100). The program should generate a random number between 0 and 100 and then the user will try to guess the number. The program should help the user guess the number (see details below). The program must allow the user five attempts to guess the number. Further Instruction: (a) Declare a variable diff and assign to it the...
module traffic(a, b,clk, reset, P1, P2, PL1, PL2, ind); input a,b; input clk; //g=100 y=010 r=001...
module traffic(a, b,clk, reset, P1, P2, PL1, PL2, ind); input a,b; input clk; //g=100 y=010 r=001 input reset; //g for pedes = 000 red = 111 input ind; output[2:0] P1; output[2:0] P2; // two roads output[1:0] PL1; //Pl is pedestrian output[1:0] PL2; reg [2:0] P1; reg [2:0] P2; reg [1:0] PL1; reg [1:0] PL2; reg [2:0] sig; always @(posedge clk, posedge reset) if(reset) begin P1 <= 3'b100; P2 <= 3'b001; PL1 <= 3'b111; PL2 <= 3'b000; end else begin //...
Given Y=120, TR=10, C=70, T=40, G=45. Total S (saving) = ____. Select one: A. 3 B....
Given Y=120, TR=10, C=70, T=40, G=45. Total S (saving) = ____. Select one: A. 3 B. 5 C. 7 D. 9 E. 11
Design a combinational circuit with four inputs (A, B, C and D) and four outputs (W, X, Y and Z). When the binary input is less than 10 the binary output is two greater than the input. When the binary input is equal or greater than 10 the binary output
Design a combinational circuit with four inputs (A, B, C and D) and four outputs (W, X, Y and Z). When the binary input is less than ten the binary output is two greater than the input. When the binary input is equal or greater than ten the binary output is three less than the input.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT