Advertisement
operationBirdNet

readme.txt -- for exps-have-numbers-ss

Aug 28th, 2015
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.62 KB | None | 0 0
  1. readme.txt -- for exps-have-numbers-ss
  2.  
  3. THE TASK
  4.  
  5. In this task modify SpreadSheet.java so that numbers can be directly
  6. entered as expression operands in formulas, freely mixed with cell
  7. references.
  8.  
  9. For this task, a number is defined as a character string
  10. that can be interpreted as a double value using Java's
  11. Scanner::nextDouble() method WITH THE EXCEPTIONS that you may assume
  12.  
  13.  
  14.  
  15. 1. Operator characters (in particular "+" and "-") are not present,
  16. so all numbers are non-negative, and there are no embedded
  17. operators, as in 1.3e-6 and 2e+5.
  18. REED'S NOTES:
  19. 1) Info on Operator characters: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/opsummary.html
  20. 2) non-negative: either positive or equal to zero.
  21. 3) embedded operators: Translation?
  22.  
  23. 2. SignedNonNumbers such as NaN and Infinity are not present.
  24. REED'S NOTES:
  25. 1) SignedNonNumbers: Translation?
  26. 2) NaN: not a number, a numeric data type value representing an undefined or
  27. unrepresentable value(especially in floating-point calculations).
  28.  
  29. Video demonstrations of a solution for this task are available.
  30. 1. During the exam: as exps-have-numbers-ss.html in the "Solution Demonstration Videos"
  31. folder on the desktop in the exam delivery environment.
  32. 2. During exam preparation, outside the exam environment.
  33. https://s3-us-west-2.amazonaws.com/proxor-video/video/exps-have-numbers-ss-transcoded.mp4
  34.  
  35. REED'S NOTES:
  36.  
  37. ***SCANNER***
  38.  
  39. 1) Simple text scanner, can parse primitive types & strings using regular expressions.
  40.  
  41. 2) Scanner breaks input into tokens using delimiter pattern(default matches whitespace).
  42.  
  43. 3) The resulting tokens may then be converted into values of different types using the various *NEXT METHODS*.
  44.  
  45. EX:
  46. // allows a user to read a number from System.in
  47. Scanner sc = new Scanner(System.in);
  48. int i = sc.nextInt();
  49.  
  50. EX:
  51. // allows long types to be assigned from entries in a file myNumbers
  52. Scanner sc = new Scanner(new File("myNumbers"));
  53. while (sc.hasNextLong()) {
  54. long aLong = sc.nextLong();
  55. }
  56.  
  57. 4) Scanner can use delimiters other than whitespace.
  58.  
  59. EX:
  60. // reads several items in from a string:
  61.  
  62. String input = "1 fish 2 fish red fish blue fish";
  63. Scanner s = new Scanner(input).useDelimiter("\\s*fish\\s*");
  64. System.out.println(s.nextInt());
  65. System.out.println(s.nextInt());
  66. System.out.println(s.next());
  67. System.out.println(s.next());
  68. s.close();
  69.  
  70. Output:
  71.  
  72. 1
  73. 2
  74. red
  75. blue
  76.  
  77. 5) Same output can be generated with code bellow,
  78. uses regular expression to parse all four tokens at once:
  79.  
  80. EX:
  81. String input = "1 fish 2 fish red fish blue fish";
  82. Scanner s = new Scanner(input);
  83. s.findInLine("(\\d+) fish (\\d+) fish (\\w+) fish (\\w+)");
  84. MatchResult result = s.match();
  85. for (int i=1; i<=result.groupCount(); i++)
  86. System.out.println(result.group(i));
  87. s.close();
  88.  
  89. 6) more on Scanner:
  90.  
  91. http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html
  92.  
  93. REED'S NOTES:
  94.  
  95. ***NEXTDOUBLE()***
  96.  
  97. 1) Scans the next token of the input as a double.
  98.  
  99. 2) Returns the double scanned from the input.
  100.  
  101. 3) will throw InputMismatchException if the next token cannot
  102. be translated into a valid double value.
  103. If the translation is successful,
  104. the scanner advances past the input that matched.
  105.  
  106. 4)
  107.  
  108. EX:
  109.  
  110. public static void main(String[] args) {
  111.  
  112. String s = "Hello World! 3 + 3.0 = 6 true";
  113.  
  114. // create a new scanner with the specified String Object
  115. Scanner scanner = new Scanner(s);
  116.  
  117. // use US locale to be able to identify doubles in the string
  118. scanner.useLocale(Locale.US);
  119.  
  120. // find the next double token and print it
  121. // loop for the whole scanner
  122. while (scanner.hasNext()) {
  123.  
  124. // if the next is a double, print found and the double
  125. if (scanner.hasNextDouble()) {
  126. System.out.println("Found :" + scanner.nextDouble());
  127. }
  128.  
  129. // if a double is not found, print "Not Found" and the token
  130. System.out.println("Not Found :" + scanner.next());
  131. }
  132.  
  133. // close the scanner
  134. scanner.close();
  135. }
  136.  
  137. OUTPUT:
  138.  
  139. Not Found :Hello
  140. Not Found :World!
  141. Found :3.0
  142. Not Found :+
  143. Found :3.0
  144. Not Found :=
  145. Found :6.0
  146. Not Found :true
  147.  
  148.  
  149. 5) more on nextDouble():
  150.  
  151. http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#nextDouble()
  152.  
  153. REED'S NOTES:
  154.  
  155. ***EXCEPTIONS you may assume***
  156.  
  157. 1) InputMismatchException -- if the next token does not match the Float regular expression, or is out of range
  158.  
  159. 2) NoSuchElementException -- if the input is exhausted
  160.  
  161. 3) IllegalStateException -- if this scanner is closed
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement