http://www.cs.umd.edu/class/fall2014/cmsc131-34/Projects/Mascots/Mascots-Project
ID: 3568516 • Letter: H
Question
http://www.cs.umd.edu/class/fall2014/cmsc131-34/Projects/Mascots/Mascots-Project-Description.pdf
This also provides the outline in which the program should be presented and gives hints as to what statements to use, how it will be graded (rubric), etc.
Here are the instructions that MUST not be changed and are already incorporated into the program:
----------------------------------------------------------------------------------------------------------------------------------------------------
import java.util.Scanner;
/*
* add comments as needed but all executable code must appear
* between the two large comment blocks below.
*/
public class MascotQuiz {
public static void main(String[] args) {
int score = 0;
String greeting =
"In this game, I ask you four questions about mascots for "
+"US collegiate sports teams." +
" You get 1 point for each correct answer, "
+"0 points if you type don't know, "
+"and you lose a point for wrong answers.";
final String schoolOptions = "University of Michigan, "
+"University of Nebraska, "
+"University of Oklahoma, "
+"University of Wisconsin";
final String mascotOptions =
"Badgers, Cornhuskers, Sooners, Wolverines";
String prompt1 =
" Type 1 and I'll give you the mascot and "
+"you give give the school. "
+"Type 2 and I'll give you the school and "
+"you give me the mascot. "
+"Type 3 and I'll quit.";
System.out.println( greeting );
----------------------------------------------------------------------------------------------------------------------------------
Explanation / Answer
import java.util.Scanner;
/*
* add comments as needed but all executable code must appear
* between the two large comment blocks below.
*/
public class MascotQuiz {
public static void main(String[] args) {
int score = 0;
String greeting =
"In this game, I ask you four questions about mascots for "
+"US collegiate sports teams." +
" You get 1 point for each correct answer, "
+"0 points if you type don't know, "
+"and you lose a point for wrong answers.";
final String schoolOptions = "University of Michigan, "
+"University of Nebraska, "
+"University of Oklahoma, "
+"University of Wisconsin";
final String mascotOptions =
"Badgers, Cornhuskers, Sooners, Wolverines";
String prompt1 =
" Type 1 and I'll give you the mascot and "
+"you give give the school. "
+"Type 2 and I'll give you the school and "
+"you give me the mascot. "
+"Type 3 and I'll quit.";
System.out.println( greeting );
/*************************************************************
* Do NOT delete, move, or change the lines of code above this:
* All of your code should appear between these comments.
************************************************************/
Scanner in = new Scanner(System.in);
int schoolCounter = 1;
String correctAnswer = "";
String question = "";
int x;
do{
System.out.println( prompt1 ); //prompt the user
x = in.nextInt(); //get the selection
in.nextLine(); //clear input buffer
if (x==1){ //if selection 1 then parse which school we are on and present question
System.out.println("Answer with one of: " + schoolOptions + schoolCounter);
if ( schoolCounter == 1){
question = "Sooners";
correctAnswer = "University of Oklahoma";
}
else if (schoolCounter == 2) {
question = "Badgers";
correctAnswer = "University of Wisconsin";
}
else if (schoolCounter == 3) {
question = "Wolverines";
correctAnswer = "University of Michigan";
}
else if (schoolCounter == 4) {
question = "Cornhuskers";
correctAnswer = "University of Nebraska";
}
}
else if (x==2){ //if selection 2 parse which school we are on and ask question
System.out.println("Answer with one of: " + mascotOptions);
if ( schoolCounter == 1){
question = "University of Oklahoma";
correctAnswer = "Sooners";
}
else if (schoolCounter == 2) {
question = "University of Wisconsin";
correctAnswer = "Badgers";
}
else if (schoolCounter == 3) {
question = "University of Michigan";
correctAnswer = "Wolverines";
}
else if (schoolCounter == 4) {
question = "University of Nebraska";
correctAnswer = "Cornhuskers";
}
}
schoolCounter++; //increment which school we are on
//only get answer if not quitting
if (x!=3) {
System.out.print(question + " ? => ");
String answer = in.nextLine();
if ("don't know".equalsIgnoreCase(answer)){
//no score, nothing happens
}
else if (correctAnswer.equals(answer)){
score++; //correct answer, get 1 point
}
else{
score--; //incorrect answer, deduct 1 point
}
}
//only ask to quit if have gone through all schools and not if we are quitting
if (schoolCounter == 5 && x<3) {
System.out.print( " Want to play again? (type yes or no): " );
String play = in.nextLine();
if (play.equalsIgnoreCase("no")){
x = 3;
}
else{
schoolCounter = 1;
score = 0;
}
}
}
while (x!=3);
/*************************************************************
* Do NOT delete, move, or change this next line of code:
* This should be the last line of code in your program!
************************************************************/
System.out.println( " Bye. Your score is " + score );
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.