Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package person;
- public class Student {
- int age = 15;
- String s = "Patrick's age is " + age;
- int year = 1999;
- String s1 = "Patrick's year is " + year;
- {
- Major Major = new Major();
- String s = Major.toString();
- }
- }
- package person;
- public class Instrctor {
- int age = 35;
- String s = "Jake's age is " + age;
- int year = 1984;
- String s1 = "jake's year is " + year;
- {
- Salary Salary = new Salary();
- String s = Salary.toString();
- }
- }
- public class AnyCorrectChoiceQuestion {
- private String text;
- private String answer;
- public AnyCorrectChoiceQuestion()
- {
- text = "";
- answer = "";
- }
- public void setText(String questionText)
- {
- text = questionText;
- }
- public void setAnswer(String correctResponse)
- {
- answer = correctResponse;
- }
- public boolean checkAnswer(String response)
- {
- return response.equals(answer);
- }
- public void display()
- {
- System.out.println(text);
- }
- }
- import java.util.Scanner;
- public class Demo1
- {
- public static void main(String[] args)
- {
- Scanner in = new Scanner(System.in);
- AnyCorrectChoiceQuestion q = new AnyCorrectChoiceQuestion();
- q.setText("What is 2 + 2?");
- q.setAnswer("4");
- q.display();
- System.out.print("4");
- String response = in.nextLine();
- String response = null;
- System.out.println(q.checkAnswer(response));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment