Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class TriviaUpdated
  3.  
  4. {
  5. private String question;
  6. private String answer;
  7. public TriviaUpdated(String question,String answer){
  8.  
  9. this.question=question;
  10. this.answer=answer;
  11. }
  12. public String getQuestion() {
  13. return question;
  14. }
  15. private void setQuestion(String question) {
  16. this.question = question;
  17. }
  18. public String getAnswer() {
  19. return answer;
  20. }
  21. private void setAnswer(String answer) {
  22. this.answer = answer;
  23. }
  24. public String toString()
  25. {
  26. return "question :"+this.question+"\nanswer :"+this.answer;
  27. }
  28. public static void main(String[] args)
  29. {
  30. Scanner keyboard = new Scanner(System.in);
  31. TriviaUpdated t = new TriviaUpdated("Capital of USA", "Washington");
  32. System.out.println("What is the : " + t.getQuestion());
  33. System.out.print("Enter your answer: ");
  34. String answer = keyboard.nextLine();
  35.  
  36.  
  37. if(answer.equalsIgnoreCase(t.getAnswer())){
  38. System.out.println("That's right - congratulations!");
  39.  
  40. }else{
  41. System.out.println("I'm sorry, that's not correct.");
  42. System.out.println("The correct answer is: "+t.getAnswer());
  43. }
  44.  
  45. System.out.println(t.toString());
  46. TriviaUpdated t2 = new TriviaUpdated("Capital of Paris", "France");
  47. System.out.println("What is the: " + t2.getQuestion());
  48. System.out.print("Enter your answer: ");
  49. String answer2 = keyboard.nextLine();
  50.  
  51. if(answer2.equalsIgnoreCase(t2.getAnswer())){
  52. System.out.println("That's right - congratulations!");
  53.  
  54. }else{
  55. System.out.println("I'm sorry, that's not correct.");
  56. System.out.println("The correct answer is: "+t2.getAnswer());
  57. }
  58. System.out.println(t2.toString());
  59. }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement