Question

"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

import java.util.Scanner;

public class SimonSays {
   public static void main (String [] args) {
      Scanner scnr = new Scanner(System.in);
      String simonPattern;
      String userPattern;
      int userScore;
      int i;

      userScore = 0;

      simonPattern = scnr.next();
      userPattern = scnr.next();

      /* Your solution goes here */

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

      return;
   }
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;

public class SimonSays {

    public static void main(String[] args) {
        Scanner scnr = new Scanner(System.in);
        String simonPattern;
        String userPattern;
        int userScore;
        int i;
        userScore = 0;
        simonPattern = scnr.next();
        userPattern = scnr.next();
        for (i = 0; i < simonPattern.length(); ++i) {
            if (simonPattern.charAt(i) != userPattern.charAt(i)) {
                break;
            } else {
                userScore++;
            }
        }
        System.out.println("userScore: " + userScore);
        return;
    }
}
Add a comment
Know the answer?
Add Answer to:
"Simon Says" is a memory game where "Simon" outputs a sequence of 10 characters (R, G,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • CHALLENGE ACTIVITY 4.8.1: Simon says Simon Says" is a memory game where Simon outputs a sequence...

    CHALLENGE ACTIVITY 4.8.1: Simon says 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 1 import java.util.Scanner; 3 public class...

  • "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>...

  • Plz use c language "Simon Says" is a memory game where "Simon" Outputs a sequence of...

    Plz use c language "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 user Score Upon a mismatch, exit the loop using a break statement Ex The following patterns yield a user Score of 4: simon Pattern: R, R, G, B, R, Y, Y,...

  • this is a c++ question. just need to do the part that says student code. Complete...

    this is a c++ question. just need to do the part that says student code. Complete the do-while loop to output 0 to countLimit. Assume the user will only input a positive number. Sample program: #include using namespace std; int main() { int countLimit = 0; int printVal = 0; // Get user input cin >> countLimit; printVal = 0; do { cout << printVal << " "; printVal = printVal + 1; } while ( ); cout << endl;...

  • CHALLENGE ACTIVITY 3.11.1: Using boolean. D Assign is Teenager with true if kidAge is 13 to...

    CHALLENGE ACTIVITY 3.11.1: Using boolean. D Assign is Teenager with true if kidAge is 13 to 19 inclusive. Otherwise, assign is Teenager with false. 1 import java.util.Scanner; 3 public class TeenagerDetector 1 public static void main (String [] args) { Scanner scnr = new Scanner(System.in); boolean isTeenager; int kidAge; D}]oll kidage = scnr.nextInt(); /* Your solution goes here */ Go USB if (isTeenager) { System.out.println("Teen"); else { System.out.println("Not teen"); 20 Run Feedback? CHALLENGE ACTIVITY 3.11.2: Boolean in branching statements. Write...

  • Write a statement that outputs variable numTickets. End with a newline. import java.util.Scanner; public class VariableOutput...

    Write a statement that outputs variable numTickets. End with a newline. import java.util.Scanner; public class VariableOutput ( public static void main (String D args) int numTickets; Scanner scnr new Scanner(System.in) scnr.nextint0:I/ Program will be tested with values: 15, 40. numTickets / Your solution goes here/

  • LAB: What order? (generic methods)

    13.4 LAB: What order? (generic methods)Define a generic method called checkOrder() that checks if four items are in ascending, neither, or descending order. The method should return -1 if the items are in ascending order, 0 if the items are unordered, and 1 if the items are in descending order.The program reads four items from input and outputs if the items are ordered. The items can be different types, including integers, Strings, characters, or doubles.Ex. If the input is:bat hat mat sat 63.2 96.5 100.1 123.5the output...

  • Please help....the only line that can be modified is /* Your solution goes here */. Everything...

    Please help....the only line that can be modified is /* Your solution goes here */. Everything else should remain the same. I submitted hasDigit = Character.isDigit(passCode.charAt(3)); but it's wrong....thank you import java.util.Scanner; public class CheckingPasscodes { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); boolean hasDigit; String passCode; hasDigit = false; passCode = scnr.next(); /* Your solution goes here */ if (hasDigit) { System.out.println("Has a digit."); } else { System.out.println("Has no digit."); } } }

  • Complete the do-while loop to output 0 to countLimit. Assume the user will only input a...

    Complete the do-while loop to output 0 to countLimit. Assume the user will only input a positive number. import java.util.Scanner; public class CountToLimit { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int countLimit = 0; int printVal = 0; // Get user input countLimit = scnr.nextInt(); printVal = 0; do { System.out.print(printVal + " "); printVal = printVal + 1; } while ( /* Your solution goes here */ ); System.out.println(""); return; } }

  • Answer in JAVA 1. Complete the method definition to output the hours given minutes. Output for...

    Answer in JAVA 1. Complete the method definition to output the hours given minutes. Output for sample program: 3.5 import java.util.Scanner; public class HourToMinConv {    public static void outputMinutesAsHours(double origMinutes) {       /* Your solution goes here */    }    public static void main (String [] args) {       Scanner scnr = new Scanner(System.in);       double minutes;       minutes = scnr.nextDouble();       outputMinutesAsHours(minutes); // Will be run with 210.0, 3600.0, and 0.0.       System.out.println("");    } } 2....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT