Question

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 SimonSays 1 test passed 4 public static void main (String [] args) String simonPattern; String userPattern; int userScore; int i 6 All tests passed 9 10 userscore = 0 simonPatternRRGBRYYBGY; userPatternRRGBBRYBGY; 12 13 15 16 17 18 19 20 /* Your solution goes here System.out.println(userScore:userScore); return; Run

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi.. I have written the program for simon pattern matching using for loop.

SimonSays.java

import java.util.Scanner;

public class SimonSays {

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner input = new Scanner(System.in);

String simonPattern;

String userPattern;

int userScore = 0;

int i=0;

System.out.print("Enter Simon Pattern:");

simonPattern = input.next().toUpperCase();

System.out.print("Enter User Pattern:");

userPattern = input.next().toUpperCase();

if(simonPattern.length() == userPattern.length()){

for(i=0;i

if(simonPattern.charAt(i)==userPattern.charAt(i)){

userScore++;

}else{

break;

}

}

}else{

System.out.println("Both pattern lengths are not equal");

}

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

}

}

Output:

Enter Simon Pattern:RRGBRYYBGY
Enter User Pattern:RRGBBRYGBY
User score: 4

Please check the code and let me know any querries. Thank you. All the best.

Add a comment
Know the answer?
Add Answer to:
CHALLENGE ACTIVITY 4.8.1: Simon says Simon Says" is a memory game where Simon outputs a sequence...
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
  • "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;...

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

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

    Feedback CHALLENGE ACTIVITY 3.8.1: Using boolean 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 { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); boolean isTeenager; int kidAge; kidAge - scnr.nextInt(); /* Your solution goes here */ if (isTeenager) { System.out.println("Teen"); else { System.out.println("Not teen"); 19 20 ) ) Run Feed CHALLENGE ACTIVITY 3.8.2: Boolean in branching statements. - r

  • CHALLENGE ACTIVITY 3.5.1: Detect specific values. Write an expression that prints "Special number if specialNum is-99,...

    CHALLENGE ACTIVITY 3.5.1: Detect specific values. Write an expression that prints "Special number if specialNum is-99, 0, or 44. 1 import java.util.Scanner; 3 public class Find SpecialValue { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int specialNum; specialNum - scnr.nextInt(); POSLOVOU if (/* Your solution goes here */) { System.out.println("Special number"); else { System.out.println("Not special number"); Run View your last submission

  • CHALLENGE ACTIVITY 3.4.2: Detect number range. Write an expression that prints "Eligible" if userAge is between...

    CHALLENGE ACTIVITY 3.4.2: Detect number range. Write an expression that prints "Eligible" if userAge is between 18 and 25 inclusive. Ex: 17 prints "Ineligible", 18 prints "Eligible". 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 import java.util.Scanner; public class AgeChecker { public static void main (String [] args) { int userAge = 0; userAge = 17; if( /* Your solution goes here */ ){ System.out.println("Eligible"); } else{ System.out.println("Ineligible"); } return; }...

  • CHALLENGE ACTIVITY 7.16.1: Enter the output of the ArrayList ADT functions. Jump to level 1 Type...

    CHALLENGE ACTIVITY 7.16.1: Enter the output of the ArrayList ADT functions. Jump to level 1 Type the program's output import java.util.ArrayList; import java.util.Scanner; public class IntegerManager ( public static void printSize(ArrayList<Integer> numsList) System.out.println(numsList.size() + "items"); public static void main(String[] args) Scanner scnr = new Scanner(System.in); int currval; ArrayList<Integer> intList = new ArrayList<Integer>(); Input 123-1 printSize (intList); Output currval = scnr.nextInt(); while (currval >= 0) { intList.add(currval); currval = scnr.nextInt(); printSize (intList); intList.clear(); printSize (intList); 1 2 Check Next

  • Please put the answer for the space where it says: *your solution only* i cant edit...

    Please put the answer for the space where it says: *your solution only* i cant edit anything before of after it Write an if-else statement for the following: If userTickets is greater than 5, execute award Points = 10. Else, execute award Points = userTickets. Ex if userTickets is 14, then award Points = 10. 1 import java.util.Scanner; args) { 3 public class TicketCounter { public static void main(String int anordPoints; int userTickets; Scanner ser-new Scanner(System.in); userTickets - scnr .nextInto:...

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