Advertisement
Guest User

Sonu

a guest
Mar 30th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.50 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. public class Chapter4 {
  4.  
  5. void exercise1() {
  6.  
  7. Date myDateOne = new Date(84,0,29); //creates object
  8. Date myDateTwo = new Date(85,1,15);
  9. boolean x = myDateTwo.after(myDateOne);
  10. System.out.println(x);
  11.  
  12.  
  13. }
  14. void exercise2() {
  15.  
  16. String myText = null; System.out.println("Please enter a word:"); BufferedReader x = new BufferedReader(new InputStreamReader(System.in)); try{
  17. myText = x.readLine(); }catch(IOException e){
  18. System.out.println("Error: " + e); }
  19. System.out.println(myText);
  20.  
  21. }
  22. void exercise3() {
  23.  
  24. String myGuess = null ;
  25. int points = 0 ;
  26. int overallpoints = 0 ;
  27. BufferedReader x = new BufferedReader(new InputStreamReader(System.in));
  28. System.out.println();
  29. System.out.print("What Year is it? ");
  30. System.out.println("A - 2015");
  31. System.out.println("B - 2016");
  32. System.out.println("C - 2017");
  33.  
  34. System.out.println("Enter your answer:");
  35. try {
  36. myGuess = x.readLine();//read and place value into myGuess variable
  37. }catch(IOException e){
  38. System.out.println("Error: " );
  39. }
  40.  
  41.  
  42.  
  43. if(myGuess.equals("A") || myGuess.equals("a")){ //selection to identify
  44. System.out.println(""); //variable value
  45. System.out.println("That is incorrect!");
  46. } else if(myGuess.equals("B") || myGuess.equals("b")){
  47. System.out.println("");
  48. System.out.println("That is incorrect!");
  49. } else if(myGuess.equals("C") || myGuess.equals("d")){
  50. System.out.println("");
  51. System.out.println("That is correct");
  52. points++ ;
  53. System.out.println();
  54.  
  55.  
  56. }
  57.  
  58.  
  59. String myGuess1 = null;
  60. BufferedReader xy = new BufferedReader(new InputStreamReader(System.in));
  61.  
  62. System.out.println("When was the WWW created?");
  63. System.out.println("A - 1990");
  64. System.out.println("B - 1991");
  65. System.out.println("C - 1992");
  66. System.out.println("D - 1993");
  67. System.out.println("Enter your answer (letter):");
  68.  
  69. try{
  70. myGuess = x.readLine();
  71. }catch(IOException e){
  72. System.out.println("Error: " + e);
  73. }
  74.  
  75. if(myGuess.equals("A") || myGuess.equals("a")){
  76. System.out.println("");
  77. System.out.println("That is incorrect!");
  78. } else if(myGuess.equals("B") || myGuess.equals("b")){
  79. System.out.println("");
  80. System.out.println("That is correct!");
  81. } else if(myGuess.equals("C") || myGuess.equals("d")){
  82. System.out.println("");
  83. System.out.println("That is correct!");
  84. } else if(myGuess.equals("D") || myGuess.equals("d")){
  85.  
  86. points++;
  87. System.out.println("");
  88. System.out.println("That is correct!");
  89. }
  90.  
  91. //<-------Just repeat from here for each question
  92.  
  93. System.out.println("Who invented the WWW?");
  94. System.out.println("A - Sir Tim Berners-Lee");
  95. System.out.println("B - Tim Berners-Lee");
  96. System.out.println("C – Bobby Bill Right");
  97. System.out.println("D – James May");
  98. System.out.println("Enter your answer (letter):");
  99. try{
  100. myGuess = x.readLine();
  101. }catch(IOException e){
  102. System.out.println("Error: " + e);
  103. }
  104.  
  105. if(myGuess.equals("A") || myGuess.equals("a")){ //don’t forget to change
  106. System.out.println("");
  107. points++ ;
  108. //the answers
  109. System.out.println("That is correct!");
  110. } else if(myGuess.equals("B") || myGuess.equals("b")){
  111. System.out.println("");
  112. System.out.println("That is incorrect!");
  113. } else if(myGuess.equals("C") || myGuess.equals("d")){
  114. System.out.println("");
  115. System.out.println("That is incorrect!");
  116. } else if(myGuess.equals("D") || myGuess.equals("d")){
  117. System.out.println("");
  118. System.out.println("That is incorrect!");
  119. }
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127. System.out.println("When did England win the world cup?");
  128. System.out.println("A - 1966");
  129.  
  130. points++ ;
  131. System.out.println("B - 1989");
  132. System.out.println("C – 1978");
  133. System.out.println("D – 1787");
  134. System.out.println("Enter your answer (letter):");
  135. try{
  136. myGuess = x.readLine();
  137. }catch(IOException e){
  138. System.out.println("Error: " + e);
  139. }
  140.  
  141. if(myGuess.equals("A") || myGuess.equals("a")){ //don’t forget to change
  142. System.out.println("");
  143. ;//the answers
  144. System.out.println("That is correct!");
  145. } else if(myGuess.equals("B") || myGuess.equals("b")){
  146. System.out.println("");
  147. System.out.println("That is incorrect!");
  148. } else if(myGuess.equals("C") || myGuess.equals("d")){
  149. System.out.println("");
  150. System.out.println("That is incorrect!");
  151. } else if(myGuess.equals("D") || myGuess.equals("d")){
  152. System.out.println("");
  153. System.out.println("That is incorrect!");
  154. }
  155.  
  156.  
  157. System.out.println("Who is Niam Pabari");
  158. System.out.println("A - A student");
  159. System.out.println("B - A teacher");
  160. System.out.println("C – A master");
  161. System.out.println("D – A fighter");
  162. System.out.println("Enter your answer (letter):");
  163. try{
  164. myGuess = x.readLine();
  165. }catch(IOException e){
  166. System.out.println("Error: " + e);
  167. }
  168.  
  169. if(myGuess.equals("A") || myGuess.equals("a")){ //don’t forget to change
  170. System.out.println("");
  171. points++ ;//the answers
  172. System.out.println("That is correct!");
  173. } else if(myGuess.equals("B") || myGuess.equals("b")){
  174. System.out.println("");
  175. System.out.println("That is incorrect!");
  176. } else if(myGuess.equals("C") || myGuess.equals("d")){
  177. System.out.println("");
  178. System.out.println("That is incorrect!");
  179. } else if(myGuess.equals("D") || myGuess.equals("d")){
  180. System.out.println("");
  181. System.out.println("That is incorrect!");
  182. }
  183.  
  184.  
  185.  
  186.  
  187. //<-------End of repeat
  188.  
  189.  
  190. System.out.println("Total points " + points ) ;
  191.  
  192. }
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199. void question2() {
  200. String myGuess = null ;
  201. int points = 0 ;
  202. int overallpoints = 0 ;
  203. BufferedReader x = new BufferedReader(new InputStreamReader(System.in));
  204. System.out.println();
  205. System.out.print("What Month is it? ");
  206. System.out.println("A - Jan");
  207. System.out.println("B - Feb");
  208. System.out.println("C - Mar");
  209.  
  210. System.out.println("Enter your answer:");
  211. try {
  212. myGuess = x.readLine();//read and place value into myGuess variable
  213. }catch(IOException e){
  214. System.out.println("Error: " );
  215. }
  216.  
  217.  
  218.  
  219. if(myGuess.equals("A") || myGuess.equals("a")){ //selection to identify
  220. System.out.println(""); //variable value
  221. System.out.println("That is incorrect!");
  222. } else if(myGuess.equals("B") || myGuess.equals("b")){
  223. System.out.println("");
  224. System.out.println("That is incorrect!");
  225. } else if(myGuess.equals("C") || myGuess.equals("d")){
  226. System.out.println("");
  227. System.out.println("That is correct");
  228. System.out.println();
  229.  
  230.  
  231. }
  232.  
  233. if (myGuess == "C") {
  234.  
  235. overallpoints = points + 1 ;
  236.  
  237. System.out.println("You have " + overallpoints + "points");
  238.  
  239. }
  240.  
  241. }
  242.  
  243.  
  244.  
  245.  
  246.  
  247. void exercise5() {
  248. Scanner scanner = new Scanner(System.in);
  249.  
  250. String username = null ;
  251. String Password = null ;
  252.  
  253. System.out.println();
  254. System.out.print(" Username: ");
  255. username = scanner.next();
  256. System.out.println();
  257. System.out.print(" Password: ");
  258. Password = scanner.next();
  259.  
  260. if (username.equals("admin") && Password.equals("letmein")) {
  261.  
  262. System.out.println();
  263. System.out.print(" Access Granted");
  264.  
  265.  
  266. }
  267. else {
  268.  
  269. System.out.println();
  270. System.out.println(" Access Denied");
  271. }
  272. }
  273.  
  274. void exercise6 () {
  275.  
  276. Scanner scanner = new Scanner(System.in);
  277. int Years ;
  278. int Points ;
  279.  
  280. System.out.println();
  281. System.out.print("How many years have you been driving for?");
  282. Years = scanner.nextInt();
  283. System.out.println();
  284. System.out.print("How many points do you have?");
  285. Points = scanner.nextInt();
  286.  
  287.  
  288. if ((Years <=2 && Points >= 6) || (Years >=2 && Points >=12))
  289. {
  290.  
  291. System.out.println();
  292. System.out.print("Your Licence is disqualifed!");
  293.  
  294. }
  295. else {
  296.  
  297. System.out.println();
  298. System.out.print("Your Licence is Safe!");
  299.  
  300. }
  301.  
  302.  
  303. }
  304.  
  305. void exercise7 () {
  306.  
  307. Scanner scanner = new Scanner(System.in);
  308.  
  309. double Number1 ;
  310. double Number2 ;
  311. double Sum ;
  312. String add , subtract , divide , multiply ;
  313. String Chosenoperation = null ;
  314.  
  315. System.out.println();
  316. System.out.print("What would your first number to be?");
  317. Number1 = scanner.nextInt();
  318. System.out.println();
  319. System.out.print("What would you like your second number to be?");
  320. Number2 = scanner.nextInt();
  321.  
  322. System.out.println();
  323. System.out.print("What Operation would you like to do to your numbers?");
  324. Chosenoperation = scanner.next();
  325.  
  326. if (Chosenoperation.equals("add")) {
  327. System.out.println();
  328. System.out.print(Number1 + Number2);
  329.  
  330.  
  331. }
  332.  
  333. if (Chosenoperation.equals("subtract")) {
  334.  
  335. System.out.println();
  336. System.out.print(Number1 - Number2);
  337.  
  338. }
  339.  
  340. if (Chosenoperation.equals("divide")) {
  341. System.out.println();
  342.  
  343. Sum = Number1 / Number2 ;
  344. System.out.print(Sum);
  345.  
  346.  
  347.  
  348. }
  349.  
  350. if (Chosenoperation.equals("multiply")) {
  351. System.out.println();
  352. System.out.print(Number1 * Number2);
  353.  
  354. }
  355. }
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367. public Chapter4() {
  368. // TODO Auto-generated constructor stub
  369. exercise1();
  370. exercise2();
  371. exercise3();
  372. exercise5();
  373. exercise6();
  374. exercise7();
  375.  
  376.  
  377. }
  378.  
  379. public static void main(String[] args) {
  380. // TODO Auto-generated method stub
  381. Chapter4 attempt1 = new Chapter4();
  382.  
  383. }
  384.  
  385. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement