Advertisement
SageTheWizard

questions.java

Feb 4th, 2018
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.17 KB | None | 0 0
  1. /*
  2.   Author: Jacob Gallucci
  3.   Course: CMPSC 221
  4.   Assignment: Programming Assignment 1 - Trivia Game
  5.   Due date: 2/6/2018
  6.   File: Question.java
  7.   Purpose: Question object for csgoTrivia.java game - Contains private Qustion and Answer Strings 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.   Compiler/IDE: OpenJDK 1.8.0_151 (compiled from CLI) - Atom / Vim text editors
  14.   Operating system: Debian Stretch 9
  15.   Reference(s): https://docs.oracle.com/javase/tutorial/java/javaOO/classes.html - used to refresh on how to set up a class in java
  16. */
  17. // Question Object for csgoTrivia.java
  18. public class Question
  19. {
  20.   private String quest; // Question String for the object
  21.   private String answer; // Answer String for the object
  22.  
  23.   public Question() // Constructor will set the quest and answer strings to blank.. but will initialize the data type
  24.   {
  25.     quest = "";
  26.     answer = "";
  27.   }
  28.   public void setQuest(String text) // Sets the question string with the string passed to it
  29.   {
  30.     quest = text;
  31.   }
  32.   public void setAnswer(String correctResponse) // Sets the answer string with the string passed to it
  33.   {
  34.     answer = correctResponse;
  35.   }
  36.   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
  37.   {
  38.     return (answer.equalsIgnoreCase(response.trim())); // Ignores case and extra white spaces in front or behind the response text
  39.   }
  40.   public String displayQuestion() // Displays the quest string by returning the string
  41.   {
  42.     return (quest);
  43.   }
  44.   public String displayAnswer() // Displays the answer string by returning the string
  45.   {
  46.     return (answer);
  47.   }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement