Welcome to CS1102 sem1 08/09 ? - PowerPoint PPT Presentation


PPT – Welcome to CS1102 sem1 08/09 ? PowerPoint presentation | free to download - id: 7373ad-OTA1O


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation

Welcome to CS1102 sem1 08/09 ?


Welcome to CS1102 sem1 08/09 Notes: All of my PowerPoint s will be uploaded to my website after my last tutorial class every week. http://www.comp.nus.edu.sg ... – PowerPoint PPT presentation

Number of Views:9
Avg rating:3.0/5.0
Slides: 18
Provided by: dcs104


Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Welcome to CS1102 sem1 08/09 ?

Welcome to CS1102 sem1 08/09 ?
  • Notes
  • All of my PowerPoint slides will be uploaded to
    my website after my last tutorial class every
  • http//www.comp.nus.edu.sg/stevenha/myteaching/
  • You do not need to write down much. Your
    attention is more important!
  • This is not the official solution. The official
    solution will be uploaded by Dr Tan to IVLE
    workbin weekly.

About Me
  • Name Steven Halim
  • Indonesian Chinese
  • 5th year (err) PhD candidate _at_ SoC, NUS
  • Former hobby Programming/Studying Data
    Structures or Algorithms
  • Now this hobby is turned into Profession
  • Teaching Assistant for CS1102, sem1 08/09, class
    T3, T4, T5, and T6
  • Very important website ?? side by side with
    CS1102 IVLE
  • http//www.comp.nus.edu.sg/stevenha/myteaching/
  • For extra consultation outside this classroom
  • Timing preferably Thursday, 1-2pm (before T4) or
    5-6pm (after T6)
  • Venue TA Office COM1-2-46 (just around the
    corner, call me from outside)
  • If you feel that you need help, try to get help
    as early as possible!

About You
  • No time for full introduction
  • Lets just do some quick survey ?
  • Nationality
  • Indonesian/Singaporean/Malaysian/Chinese/Vietnames
    e/Philippines/Indian/ Bangladeshi/Pakistani?
  • Others?
  • Faculty
  • COM/CPE/Science?
  • Others?
  • Origin
  • Poly/JC/High school in your home country?
  • Others?

About This Tutorial (1)
  • Why you should attend this tutorial?
  • Tutorial attendance and participation 5 (PE
  • Please sign the attendance list.
  • Tutorial Attendance
  • Minus certain per absence
  • Tutorial Participation
  • For next tutorials, you will BID to answer at
    least one question.
  • We have 9-10 tutorials left, 3-4 questions each,
    27-40 questions to grab ?
  • You can be kiasu for todays tutorial too, 5
    questions to grab ?
  • Email me (stevenhalim_at_gmail.com), say e.g.
    Steven, I want to do T2, Q1.
  • I will confirm your bid based on
    First-Come-First-Serve basis.
  • At the end of the day, everyone gets at least one
  • If you have done one presentation, do not bid
    again until everyone gets a chance.
  • Prepare your answer in electronic format (ppt,
    word), use this PC to present!
  • No participation if you do not try at all!

About This Tutorial (2)
  • What are we going to do _at_ each tutorial?
  • Review Past Lectures (10-15 minutes)
  • Discuss Tutorial Questions (15-35 minutes)
  • Student presentations, according to the
  • gtgt Target finish in 50 minutes ltlt
  • Individual Q A (the last 10 minutes)
  • If you are too shy to ask during the session, use
    this time window
  • Best post question in IVLE for others to see! I
    will occasionally reply there

About Java and CS1102
  • Java
  • Hopefully you are familiar with it by now (revise
    your CS1101 again lec 1)
  • CS1102
  • Java is not the only thing in CS1102!
  • CS1102 is about Data Structures and
  • Not an easy module ?
  • No guarantee that you will understand the
    materials after my class
  • But lets try our best ?
  • Also, read this story later
  • http//www.comp.nus.edu.sg/rtan/articles/RavenEve

Tutorial 1 Java OO Programming
Very Quick Review
  • Problem Solving and Software Engineering
  • These stuffs will going to be revisited in
  • Java Revision
  • Too many too revise gt.lt
  • 127 slides in Lecture 1
  • However, make sure that you are familiar with all
  • Using Java, I/O (keyboard/monitor, file), Class,
    Class Inheritance, Method Overriding, Abstract
    Classes, Polymorphism Exception, Assertion
  • We will test some concepts during this tutorial.
  • I will address your individual query (if any),
    after class

Q1 Pseudocode definitionusage
  • http//en.wikipedia.org/wiki/Pseudocode

Q2 Spiral Output (1)
  • n is a perfect square if n ii i sqrt(n) i
    lt n i ? odd integer!
  • This problem is not well defined for n 22, 42,
    62, etc
  • 25 24 23 22 21 10 09 08 07 20 11 02 01 06 19 12
    03 04 05 18 13 14 15 16 17
  • Try to solve this algorithm using pseudo code
  • Actual Java code is fine, but perhaps quite
  • Easiest solution (other suggestions are
  • Use 2-D array of integers of size ii, where i2
    n, initialize the values with all 0.
  • Start from center coordinate (i/2, i/2), insert
    number 1 with direction up.
  • If my left side is 0 (not filled), turn left,
    fill the next number else if my left side is not
    0 (filled), go forward, fill the next number
  • Print the updated 2-D array

Q2 Spiral Output (2)
  • To make the result looks like this (different
  • 21 22 23 24 25 20 07 08 09 10 19 06 01 02 11 18
    05 04 03 12 17 16 15 14 13
  • You just need to change the algorithm to check
    your right side
  • The actual Java implementation may require
  • You will learn this in Lecture 5
  • My source code is uploaded to my website for
    those who wants to try

Q3 Sentence
  • Sentence is a string with words separated by
    punctuation marks and ended with a full stop.
  • http//en.wikipedia.org/wiki/Punctuation
  • Your task design these classes
  • Sentence
  • Describe a sentence using private instance
  • Have an instance method for outside world to
    see the private instance attribute above
  • Have toString() method, one word per line
  • NotSentenceException
  • User defined exception class
  • TestSentence
  • Catching IOException (for BufferedReader only)
  • Check if it is a sentence, if not, throw
  • If ok, create Sentence object and print it

Q4 Swapping (1)
  • class Swapper static void swap(int x, int y)
    int temp y y x x temp
    public static void main(String args)
    int a 1, b 2 System.out.println(a a
    , b b) swap(a, b)
    System.out.println(a a , b b)

Does not work as expected. Why?
Parameter passing in Java Pass by value
Q4 Swapping (2)
  • class Swapper static void swap(Integer x,
    Integer y) Integer temp y y x
    x temp public static void main(String
    args) int a 1, b 2
    System.out.println(a a , b b)
    swap(a, b) System.out.println(a a ,
    b b)

Also does not work as expected. Why?
We are swapping references only! The actual
content is unchanged. Moreover, Integer class is
immutable in Java.
Note swapping is important in Sorting! (Lecture
Q4 Swapping (3)
  • So what should you to do to make a and b swap
  • Dirty but easiest answer
  • Just do the swapping inline, e. g.
  • public static void main(String args) int
    a 1, b 2 System.out.println(a a
    , b b) int temp a a b b
    temp System.out.println(a a , b

Q5 Base and Derived (1)
  • Private are private!
  • Public are public!
  • Only protected needs special considerations!
  • public class Base // must be saved in
    Base.java public int bPublic protected int
    bProtect private int bPrivate public class
    Derived extends Base // must be saved in
    Derived.java public int dPublic private int
    dPrivate public class Tester // must be
    saved in Tester.java public static void
    main(String args) Base b new Base()
    Derived d new Derived()
    System.out.println(b.bPublic b.bProtect
    b.bPrivate d.dPublic

Thats All for Today
  • See you next week for an even more exciting
  • Abstract Data Types (ADT) ?
  • Using Formula 1 as background story
About PowerShow.com