Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS1101 Group1 Discussion 10 Lek Hsiang Hui comp.nus.edu.sg

Similar presentations


Presentation on theme: "CS1101 Group1 Discussion 10 Lek Hsiang Hui comp.nus.edu.sg"— Presentation transcript:

1 CS1101 Group1 Discussion 10 Lek Hsiang Hui lekhsian @ comp.nus.edu.sg http://www.comp.nus.edu.sg/~lekhsian/cs1101

2 Scope of discussion Lab8 : MyString Lab9 : Taxi PE Revision Notes about final exam

3 Lab8 : MyString http://www.comp.nus.edu.sg/~lekhsian/d1 0/MyString.javahttp://www.comp.nus.edu.sg/~lekhsian/d1 0/MyString.java Check out also the implementation of StringBuffer and StringBuilder –E.g. C:\Program Files\Java\jdk1.6.0_03\src.zip –\java\lang

4 Lab9 : Taxi Use of BufferedReader and StringTokenizer Actually Scanner provide similar capability too Code is not modular (i.e. divide your codes into different functions) –Should have a method for typeA, typeB, typeC –No check for number of parameters using args.length Take note that we are counting in blocks of distance –i.e. distance 178m would be considered as a block of 200m

5 StringTokenizer http://www.comp.nus.edu.sg/~lekhsian/d1 0/StringTokenizerExample.javahttp://www.comp.nus.edu.sg/~lekhsian/d1 0/StringTokenizerExample.java More importantly, http://java.sun.com/javase/6/docs/api/java/ util/StringTokenizer.html http://java.sun.com/javase/6/docs/api/java/ util/StringTokenizer.html

6 Lab9 : Taxi Should be only 1 java file with both classes kept in it However when you compile it there will still be 2 class files created Of course how you place the classes is quite important, the one with the main method should come first, etc http://www.comp.nus.edu.sg/~lekhsian/d1 0/FareCalculator.javahttp://www.comp.nus.edu.sg/~lekhsian/d1 0/FareCalculator.java

7 PE http://www.comp.nus.edu.sg/~lekhsian/d1 0/http://www.comp.nus.edu.sg/~lekhsian/d1 0/

8 Interface A construct that defines the behavior of a different type of Object public interface CdPlayer{ String TYPE = “CD PLAYER”; //constants (all variables will be implicitly final) public void play(); //empty method body public void stop(); } Point to know is that all the methods in an interface are abstract CD Player Example

9 Revision Primitive Data Type –What’s the range? –Declaring them (duh?!) –Comparison (char is compare using ‘ ‘ etc) –Never use float/double in loops e.g. for (double a = 0 ; a < 1.3 ; a+= 0.1){ … } –Octal, Decimal, Hexadecimal –float ( exponential case: 15.5E2f) Remember you need the ‘f’ if the value is floating value if not it will be treated as type error (double)

10 Revision Escape characters \t \n \r \\ \’ etc… Valid identifier name –Begin with _ $ letter –Followed by _ $ letter number –Case sensitive Reserved Words Remember your “;” when writing your codes

11 Revision Operators –Favorite - % / –++x, x++ –Logical operators –&& || ! Short-circuit evaluation –When comparing values (use == not =) But for String remember to use.equals() –Op= >=,, %=,+= etc Precedence and associativity (refer to table) casting

12 Revision Scanner –next(), nextLine(), nextInt() etc if-else –Do you know how to identify a particular else is for which if when it is badly indented? (dangling else) switch –Expression must be char, byte, short, int –Be careful of the break;

13 Revision ?: (cond) ? true_return : false_return; while, for, do-while (don’t forget the last ; for do-while) –break –continue Arrays (1D, 2D arrays) –traversing, revise your labs! –Copying arrays, sort, searching

14 Revision ?: (cond) ? true_return : false_return; while, for, do-while (don’t forget the last ; for do-while) –break –continue Arrays (1D, 2D arrays) –traversing, revise your labs! –Copying arrays, sort, searching

15 Revision Functions / Procedures Local variables? Formal parameters / actual parameters Return value (remember to return if the function is not void) pass by value –Case where you pass an int to a method –Case where you pass int[] into a method etc

16 Revision Selection Sort Bubble Sort Linear Search Binary Search Recursion

17 Revision Creating Classes –Constructor –Instance & class variables –extends / implements Access Rights (public, private, protected) Getters & Setters

18 Revision String –Comparing String (equals) –charAt … etc Math –Random() BufferedReader, InputStreamReader, FileReader, PrintWriter, RandomAccessFile StringTokenizer Exceptions –throw new Exception() –try-catch –throws –What type of exception will be thrown

19 Revision Interface Comparable Comparator Serializable –Why need serializable?

20 Notes about final exam Check out http://www.comp.nus.edu.sg/~chenxia2/ http://www.comp.nus.edu.sg/~chenxia2/ For suggested answers for some of the past year papers Revise all the stuff you did (*including labs*)

21 Thank you All the best for your exams!


Download ppt "CS1101 Group1 Discussion 10 Lek Hsiang Hui comp.nus.edu.sg"

Similar presentations


Ads by Google