Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Author: Jacob Gallucci
- E-mail: [email protected]
- Course: CMPSC 221
- Assignment: Programming Assignment 4 - Trivia Game Super GUI Edition
- Due date: 4/24/2018
- File: Question.java
- Purpose: Question object for csgoTriviaGUI.java game - Contains private Qustion and Answer Strings and private pointVal integers and the following fucntions
- Question() - Constructor, setQuest() - sets the question to the inputted string (from a text document)
- setAnswer() - Sets the answer to the inputted string (from a text document)
- checkAnswer() - checks answer from user input against predefined answer (ignores case and extra whitespaces)
- displayQuestion() - returns the question string for output via JOptionPane
- displayAnswer() - Returns the answer string for output via JOptionPane
- getPointVal() - Returns the point value integer for operations
- setPointVal() - Sets the point value from the inputted integer
- Compiler/IDE: OpenJDK 1.8.0_151 (compiled from CLI) - Atom / Vim text editors
- Operating system: Debian Stretch 9
- Reference(s): Classes are classes nothing was referenced to make this
- */
- // Question Object for csgoTriviaGUI.java
- public class Question
- {
- private String quest; // Question String for the object
- private String answer; // Answer String for the object
- private int pointVal; // point value of the question
- public Question() // Constructor will set the quest and answer strings to blank.. but will initialize the data type
- {
- quest = "";
- answer = "";
- pointVal = 0;
- }
- public void setQuest(String text) // Sets the question string with the string passed to it
- {
- quest = text;
- }
- public void setAnswer(String correctResponse) // Sets the answer string with the string passed to it
- {
- answer = correctResponse;
- }
- public boolean checkAnswer(String response) // Checks the user inputted answer vs. the correct answer.. returns true or false depending on if the answer is correct
- {
- return (answer.equalsIgnoreCase(response.trim())); // Ignores case and extra white spaces in front or behind the response text
- }
- public String displayQuestion() // Displays the quest string by returning the string
- {
- return (quest);
- }
- public String displayAnswer() // Displays the answer string by returning the string
- {
- return (answer);
- }
- public int getPointVal() // Returns the point value of the question
- {
- return (pointVal);
- }
- public void setPointVal(int value) // sets point value of the question
- {
- pointVal = value;
- }
- public Boolean evalUserAnswer(String userAnswer) // Evaluates user answer to a question and returns the boolean
- {
- return (answer.equalsIgnoreCase(userAnswer));
- }
- }
Add Comment
Please, Sign In to add comment