Answered step by step
Verified Expert Solution
Question
1 Approved Answer
package console_apps; import java.util.Scanner; import model.Utilities; public class RPSGameApp { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println(Enter the name of
package console_apps;
import java.util.Scanner;
import model.Utilities;
public class RPSGameApp {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter the name of player 1:");
String p1 = input.nextLine();
System.out.println("Enter the name of player 2:");
String p2 = input.nextLine();
/* Read inputs for round 1*/
System.out.println("What does " + p1 + " play at round 1 (R, P, S)?");
char p1r1 = input.nextLine().charAt(0); // reads a single character from user
System.out.println("What does " + p2 + " play at round 1 (R, P, S)?");
char p2r1 = input.nextLine().charAt(0); // reads a single character from user
/* Read inputs for round 2 */
System.out.println("What does " + p1 + " play at round 2 (R, P, S)?");
char p1r2 = input.nextLine().charAt(0); // reads a single character from user
System.out.println("What does " + p2 + " play at round 2 (R, P, S)?");
char p2r2 = input.nextLine().charAt(0); // reads a single character from user
/* Get report from the utility method. */
String report = Utilities.getRPSGameReport(p1, p2, p1r1, p2r1, p1r2, p2r2);
System.out.println(report);
input.close();
}
}
public class Utilities{
/*
* Input parameters:
* - `p1` is the name of player 1
* - `p2` is the name of player 2
* - `p1r1` is what player 1 plays in round 1 ('R', 'P', or 'S')
* - `p2r1` is what player 2 plays in round 1 ('R', 'P', or 'S')
* - `p1r2` is what player 1 plays in round 2 ('R', 'P', or 'S')
* - `p2r2` is what player 2 plays in round 2 ('R', 'P', or 'S')
*
* Assumptions:
* - `p1r1`, `p2r1`, `p1r2`, or `p2r2` is one of the following characters:
* 'R' for rock, 'P' for paper, and 'S' scissors (case-sensitive)
*
* Hints:
* - Compare character values using the relational operator ==.
* - Study the 9 test cases in TestUtilites: they are arranged in a systematic (yet not exhaustive) way.
* Q. In order to exhaustively test this game, considering how two players may play in two rounds,
* how many tests do we need? (Optionally, you may write extra test yourself as an exercise.)
*
* Refer to you lab instructions for what the method should return.
*/
public static String getRPSGameReport(String p1, String p2, char p1r1, char p2r1, char p1r2, char p2r2) {
String result = "";
/* Your implementation of this method starts here.
* Recall from Week 1's tutorial videos:
* 1. No System.out.println statements should appear here.
* Instead, an explicit, final `return` statement is placed for you.
* 2. No Scanner operations should appear here (e.g., input.nextInt()).
* Instead, refer to the input parameters of this method.
*/
/* Your implementation ends here. */
return result;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started