rockoverlord23

Untitled

Dec 4th, 2014
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. E9.8
  2. package excersize1;
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class Person
  7. {
  8.  
  9. String name;
  10. int age;
  11. Scanner actor= new Scanner(System.in);
  12.  
  13. void Person_method()
  14. {
  15. System.out.println("what's your name");
  16. name = actor.nextLine();
  17. System.out.print("how old are you");
  18. age = actor.nextInt();
  19. System.out.print("your name is " + name + " you are " + age + " years old");
  20.  
  21. }
  22.  
  23. }
  24.  
  25.  
  26.  
  27. package excersize1;
  28.  
  29. public class Employee extends Person
  30. {
  31. String job;
  32. int Salary;
  33.  
  34. void employee()
  35. {
  36.  
  37. if( age >16 )
  38. {
  39. System.out.println("what job do you have");
  40. job = actor.nextLine();
  41. System.out.println(" how much is your salary ");
  42. Salary = actor.nextInt();
  43. System.out.println("your job is " + job + " and you make " + Salary);
  44.  
  45.  
  46. } }
  47. }
  48.  
  49.  
  50. package excersize1;
  51.  
  52. public class Student extends Person
  53. {
  54. int grade;
  55. String Major;
  56.  
  57. void student()
  58. {
  59. if(age < 19){
  60.  
  61. System.out.print(" what grade are you in");
  62. grade = actor.nextInt();
  63. actor.nextLine();
  64. System.out.println("whats your Major ");
  65. Major = actor.nextLine();
  66. System.out.print(" your grade is " + grade );
  67. System.out.print(" and you major in " + Major);
  68. }
  69. }
  70.  
  71. }
  72.  
  73.  
  74.  
  75.  
  76. package excersize1;
  77.  
  78. public class Output {
  79.  
  80. public static void main(String[] args)
  81. {
  82. Person m = new Person();
  83. Employee n = new Employee();
  84. Student s = new Student();
  85. m.Person_method();
  86. n.employee();
  87. s.student();
  88.  
  89.  
  90. }
  91.  
  92. }
  93.  
  94.  
  95.  
  96. E9.4
  97.  
  98. package excersize;
  99.  
  100. public class E904 {
  101.  
  102. public static void main(String[] args)
  103. {
  104. /**
  105. A question with a text and an answer.
  106. */
  107. class Question
  108. {
  109. private String text;
  110. private String answer;
  111. private String answer1;
  112.  
  113. /**
  114. Constructs a question with empty question and answer.
  115. */
  116. public Question()
  117. {
  118. text = "what is |1|";
  119. answer = "1" ;
  120. answer1 = "-1" ;
  121. }
  122.  
  123. /**
  124. Sets the question text.
  125. @param questionText the text of this question
  126. */
  127. public void setText(String questionText)
  128. {
  129. text = questionText;
  130. }
  131.  
  132. /**
  133. Sets the answer for this question.
  134. @param correctResponse the answer
  135. */
  136. public void setAnswer(String correctResponse)
  137. {
  138. answer = correctResponse;
  139. answer1 = correctResponse;
  140. }
  141.  
  142. /**
  143. Checks a given response for correctness.
  144. @param response the response to check
  145. @return true if the response was correct, false otherwise
  146. */
  147. public boolean checkAnswer(String response)
  148. {
  149. return response.equals(answer);
  150. }
  151.  
  152. /**
  153. Displays this question.
  154. */
  155. public void display()
  156. {
  157. System.out.println(text);
  158. }
  159. }
  160.  
  161.  
  162.  
  163. }
  164.  
  165. }
Advertisement
Add Comment
Please, Sign In to add comment