import java.util.Scanner;
/*******************************************************************************
*
* ResponsibleUse program.
*
* Purpose: This program provides a solution to the "Policy for Responsible
* Use" assignment for CSCI 161. The program acts as a test that
* asks questions of the users knowledge of the policy and scores
* their answers.
*
* @author Thomas Rogers
*
* @version 1.0 (February 26, 2018)
*
******************************************************************************/
public class ResponsibleUse {
/**=========================================================================
* CLASS CONSTANTS
*
* Constants used throughout this program and their comments.
*========================================================================*/
public static final String QUESTION_1 = "Which is NOT a purpose Millersville University makes electronic resources available to faculty, staff, and students?";
public static final String RESPONSE_1A = "For conducting official University business.";
public static final String RESPONSE_1B = "For academic scholarship.";
public static final String RESPONSE_1C = "For research.";
public static final String RESPONSE_1D = "For student access to social media sites.";
public static final String ANSWER_1 = "d";
public static final String QUESTION_2 = "Which usage is NOT described in the \"Policy for Responsible Use\"?";
public static final String RESPONSE_2A = "Electronic Mail";
public static final String RESPONSE_2B = "Network Use";
public static final String RESPONSE_2C = "Crypto-currency";
public static final String RESPONSE_2D = "User Accounts";
public static final String ANSWER_2 = "c";
public static final String QUESTION_3 = "Under which topic is improper printing of documents covered?";
public static final String RESPONSE_3A = "Electronic Mail";
public static final String RESPONSE_3B = "Network Use";
public static final String RESPONSE_3C = "Webpages";
public static final String RESPONSE_3D = "Software";
public static final String ANSWER_3 = "b";
public static final String QUESTION_4 = "The \"Privacy and Confidentiality of Electronic Media\" portion of the policy states that?";
public static final String RESPONSE_4A = "The University may be required to provide information stored in its system if so compelled by a court order.";
public static final String RESPONSE_4B = "Your privacy should be presumed at all times.";
public static final String RESPONSE_4C = "The University will routinely monitor and review the contents of your user accounts.";
public static final String RESPONSE_4D = "The University does not abide by recent court decisions regarding privacy and \"Right to Know.\"";
public static final String ANSWER_4 = "a";
public static final String QUESTION_5 = "Consequences of violating the policy includes?";
public static final String RESPONSE_5A = "Loss of access to University computing systems pending disciplinary process.";
public static final String RESPONSE_5B = "Possible prosecution under State laws or local laws.";
public static final String RESPONSE_5C = "Loss of access to University computing resources after the disciplinary process.";
public static final String RESPONSE_5D = "All of the above.";
public static final String ANSWER_5 = "d";
public static final int POINTS_PER_QUESTION = 20;
public static final String POSSIBLE_RESPONSES = "abcd";
/**=========================================================================
* CLASS METHODS
*
* Program methods are listed below in alphabetical order or the order in
* which they are used in main below.
*========================================================================*/
/**
* Prints a prompt for the user to enter choice a, b, c, or d, and loops
* until they enter said then returns their input.
*
* @param console - Scanner used for user input.
* @return
*/
public static String getResponse(Scanner console) {
String resp="";
while ( ! (resp.length()==1 && POSSIBLE_RESPONSES.contains(resp)) ) {
System.out.print("Please enter a, b, c, or d: ");
resp = console.nextLine();
}
return resp;
}
/**
* Prompts the user with a supplied question along with supplied multiple choice responses,
* gets their response and if the response is correct given the supplied answer returns the
* appropriate points for that correct answer else 0 points are returned.
*
* @param console - For reading user input
* @param questionNum - integer value of the question number (e.g. 1, 2, 3).
* @param question - The question.
* @param respA - Response a.
* @param respB - Response b.
* @param respC - Response c.
* @param respD - Response d.
* @param answer - Correct answer to the question.
* @return
*/
public static int askQuestion(Scanner console, int questionNum, String question, String respA, String respB, String respC, String respD, String answer) {
System.out.printf("\nQuestion #%d: %s\n", questionNum, question);
System.out.printf("\ta. %s\n", respA);
System.out.printf("\tb. %s\n", respB);
System.out.printf("\tc. %s\n", respC);
System.out.printf("\td. %s\n", respD);
String resp = getResponse(console);
if (resp.equals(answer)) {
return POINTS_PER_QUESTION;
} else {
return 0;
}
}
/**
* Prints out the score for the user.
*
* @param totalScore
*/
public static void printScore(int totalScore) {
System.out.printf("\nYour score: %d%%\n", totalScore);
}
/**=========================================================================
* CLASS main
*
* @param args - The command-line arguments passed to the running program.
*========================================================================*/
public static void main(String[] args) {
int totalScore = 0;
Scanner console = new Scanner(System.in);
totalScore += askQuestion(console, 1, QUESTION_1, RESPONSE_1A, RESPONSE_1B, RESPONSE_1C, RESPONSE_1D, ANSWER_1);
totalScore += askQuestion(console, 2, QUESTION_2, RESPONSE_2A, RESPONSE_2B, RESPONSE_2C, RESPONSE_2D, ANSWER_2);
totalScore += askQuestion(console, 3, QUESTION_3, RESPONSE_3A, RESPONSE_3B, RESPONSE_3C, RESPONSE_3D, ANSWER_3);
totalScore += askQuestion(console, 4, QUESTION_4, RESPONSE_4A, RESPONSE_4B, RESPONSE_4C, RESPONSE_4D, ANSWER_4);
totalScore += askQuestion(console, 5, QUESTION_5, RESPONSE_5A, RESPONSE_5B, RESPONSE_5C, RESPONSE_5D, ANSWER_5);
printScore(totalScore);
}
}