Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- E9.8
- package excersize1;
- import java.util.Scanner;
- public class Person
- {
- String name;
- int age;
- Scanner actor= new Scanner(System.in);
- void Person_method()
- {
- System.out.println("what's your name");
- name = actor.nextLine();
- System.out.print("how old are you");
- age = actor.nextInt();
- System.out.print("your name is " + name + " you are " + age + " years old");
- }
- }
- package excersize1;
- public class Employee extends Person
- {
- String job;
- int Salary;
- void employee()
- {
- if( age >16 )
- {
- System.out.println("what job do you have");
- job = actor.nextLine();
- System.out.println(" how much is your salary ");
- Salary = actor.nextInt();
- System.out.println("your job is " + job + " and you make " + Salary);
- } }
- }
- package excersize1;
- public class Student extends Person
- {
- int grade;
- String Major;
- void student()
- {
- if(age < 19){
- System.out.print(" what grade are you in");
- grade = actor.nextInt();
- actor.nextLine();
- System.out.println("whats your Major ");
- Major = actor.nextLine();
- System.out.print(" your grade is " + grade );
- System.out.print(" and you major in " + Major);
- }
- }
- }
- package excersize1;
- public class Output {
- public static void main(String[] args)
- {
- Person m = new Person();
- Employee n = new Employee();
- Student s = new Student();
- m.Person_method();
- n.employee();
- s.student();
- }
- }
- E9.4
- package excersize;
- public class E904 {
- public static void main(String[] args)
- {
- /**
- A question with a text and an answer.
- */
- class Question
- {
- private String text;
- private String answer;
- private String answer1;
- /**
- Constructs a question with empty question and answer.
- */
- public Question()
- {
- text = "what is |1|";
- answer = "1" ;
- answer1 = "-1" ;
- }
- /**
- Sets the question text.
- @param questionText the text of this question
- */
- public void setText(String questionText)
- {
- text = questionText;
- }
- /**
- Sets the answer for this question.
- @param correctResponse the answer
- */
- public void setAnswer(String correctResponse)
- {
- answer = correctResponse;
- answer1 = correctResponse;
- }
- /**
- Checks a given response for correctness.
- @param response the response to check
- @return true if the response was correct, false otherwise
- */
- public boolean checkAnswer(String response)
- {
- return response.equals(answer);
- }
- /**
- Displays this question.
- */
- public void display()
- {
- System.out.println(text);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment