SageTheWizard

Question.java

Apr 23rd, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.77 KB | None | 0 0
  1. /*
  2.   Author: Jacob Gallucci
  3.   Course: CMPSC 221
  4.   Assignment: Programming Assignment 4 - Trivia Game Super GUI Edition
  5.   Due date: 4/24/2018
  6.   File: Question.java
  7.   Purpose: Question object for csgoTriviaGUI.java game - Contains private Qustion and Answer Strings and private pointVal integers and the following fucntions
  8.            Question() - Constructor, setQuest() - sets the question to the inputted string (from a text document)
  9.            setAnswer() - Sets the answer to the inputted string (from a text document)
  10.            checkAnswer() - checks answer from user input against predefined answer (ignores case and extra whitespaces)
  11.            displayQuestion() - returns the question string for output via JOptionPane
  12.            displayAnswer() - Returns the answer string for output via JOptionPane
  13.            getPointVal() - Returns the point value integer for operations
  14.            setPointVal() - Sets the point value from the inputted integer
  15.   Compiler/IDE: OpenJDK 1.8.0_151 (compiled from CLI) - Atom / Vim text editors
  16.   Operating system: Debian Stretch 9
  17.   Reference(s): Classes are classes nothing was referenced to make this
  18. */
  19. // Question Object for csgoTriviaGUI.java
  20. public class Question
  21. {
  22.   private String quest; // Question String for the object
  23.   private String answer; // Answer String for the object
  24.   private int pointVal; // point value of the question
  25.  
  26.   public Question() // Constructor will set the quest and answer strings to blank.. but will initialize the data type
  27.   {
  28.     quest = "";
  29.     answer = "";
  30.     pointVal = 0;
  31.   }
  32.   public void setQuest(String text) // Sets the question string with the string passed to it
  33.   {
  34.     quest = text;
  35.   }
  36.   public void setAnswer(String correctResponse) // Sets the answer string with the string passed to it
  37.   {
  38.     answer = correctResponse;
  39.   }
  40.   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
  41.   {
  42.     return (answer.equalsIgnoreCase(response.trim())); // Ignores case and extra white spaces in front or behind the response text
  43.   }
  44.   public String displayQuestion() // Displays the quest string by returning the string
  45.   {
  46.     return (quest);
  47.   }
  48.   public String displayAnswer() // Displays the answer string by returning the string
  49.   {
  50.     return (answer);
  51.   }
  52.   public int getPointVal()   // Returns the point value of the question
  53.   {
  54.     return (pointVal);
  55.   }
  56.   public void setPointVal(int value) // sets point value of the question
  57.   {
  58.     pointVal = value;
  59.   }
  60.   public Boolean evalUserAnswer(String userAnswer)  // Evaluates user answer to a question and returns the boolean
  61.   {
  62.     return (answer.equalsIgnoreCase(userAnswer));
  63.   }
  64.  
  65. }
Add Comment
Please, Sign In to add comment