Welcome to CS1102 sem1 08/09 Notes: All of my PowerPoint slides will be uploaded to my website after my last tutorial class every week.

Slides:



Advertisements
Similar presentations
EleUM (Electronic Learning Environment Universiteit Maastricht)
Advertisements

Simple Programs Simple Strings Writing some programs Only in Parameters? I/O Gadget.
1 CS101 Introduction to Computing Lecture 17 Algorithms II.
Copyright 2010 by Pearson Education Building Java Programs Chapter 7 Lecture 7-2: Arrays as Parameters reading: , 3.3 self-checks: Ch. 7 #5, 8,
Problem Solving 5 Using Java API for Searching and Sorting Applications ICS-201 Introduction to Computing II Semester 071.
Lecture 2 Calling and Defining Methods in Java. Introduction ●Calling and defining methods ●Declaring and defining a class ●Instances of a class ●The.
Written by: Dr. JJ Shepherd
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Procedures and Control Flow CS351 – Programming Paradigms.
CS1101: Programming Methodology
Zhang Hongyi CSCI2100B Data Structures Tutorial 2
About Me Tutor Name: Steven Halim Full-time Teaching Assistant and part-time PhD (final year?) in SoC, NUS Former Teaching Assistant for IT1005, Sem 2,
IT1005 Lab session on week 5. About your Lab TA Name: Steven Halim (Indonesian) Occupation: – Full time teaching assistant – Part time PhD student Not.
COMP171 Data Structure & Algorithm Tutorial 1 TA: M.Y.Chan.
 Monday, 9/30/02, Slide #1 CS106 Introduction to CS1 Monday, 9/30/02  QUESTIONS (on HW02, etc.)??  Today: Libraries, program design  More on Functions!
Downloading and Installing AutoCAD Architecture 2015 This is a 4 step process 1.Register with the Autodesk Student Community 2.Downloading the software.
CS 106 Introduction to Computer Science I 10 / 16 / 2006 Instructor: Michael Eckmann.
Computer Science 102 Data Structures and Algorithms V Fall 2009 Lecture 1: administrative details Professor: Evan Korth New York University 1.
WEEK 1 CS 361: ADVANCED DATA STRUCTURES AND ALGORITHMS Dong Si Dept. of Computer Science 1.
Winter 2006CISC121 - Prof. McLeod1 Welcome to CISC121 Prof. (Alan) McLeod – Web site at: All.
CS1101: Programming Methodology Aaron Tan.
1 Project 5: Median. 2 The median of a collection of numbers is the member for which there are an equal number less than or equal and greater than or.
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
CS1101: Programming Methodology
COMP Introduction to Programming Yi Hong May 13, 2015.
CLASSROOM EXPECTATIONS Ms. Bain Holgate Middle School 8 th Grade Language Arts.
Java Classes Using Java Classes Introduction to UML.
Tutorial 2 Abstract Data Types 1. Admin Stuffs Some of you request to change tutorial class… – Transfer within my own classes (T3, T4, T5, T6) is fine.
Computer Science 10: Introduction to Computer Science Dr. Natalie Linnell with credit to Cay Horstmann and Marty Stepp.
Health Class Getting Started Due Friday January 30 th Health Classroom Disclosure Human Sexuality Permission Slip Extra Credit Pre-Test Thursday Reminders.
1 Project Information and Acceptance Testing Integrating Your Code Final Code Submission Acceptance Testing Other Advice and Reminders.
Introduction to EGR115 1.Welcome! 2.Your instructors 3.Class format 4.Requirements 5.Topics 6.Grading 7.Help 1.
Welcome to CS1102C sem2 08/09 Note: All my PowerPoint slides will be uploaded to my website: after my last tutorial.
Objected Oriented Programming & Design JAVA Shishir Gupta (704) (704)
CSCI 51 Introduction to Computer Science Dr. Joshua Stough January 20, 2009.
CS1101: Programming Methodology Aaron Tan.
Welcome to CS 115! Introduction to Programming. Class URL Write this down!
Introduction to Data Structures
1 WELCOME TO COMPUTER SCIENCE 1027b COMPUTER SCIENCE FUNDAMENTALS II Lecturers: Eric Schost (001) John Barron (002)
ICS102: Introduction To Computing King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science.
CPSC 121: Models of Computation Unit 0 Introduction George Tsiknis Based on slides by Patrice Belleville and Steve Wolfman.
Principles of Computer Science I Honors Section Note Set 1 CSE 1341 – H 1.
1 CSE1301 Computer Programming: Revision. 2 Topics Type of questions What do you need to know? About the exam Exam technique Staff consultation Revision.
INTERFACES More OO Concepts. Interface Topics Using an interface Interface details –syntax –restrictions Create your own interface Remember polymorphism.
CS1101: Programming Methodology
Programming in Java CSCI-2220 Object Oriented Programming.
CS1101: Programming Methodology Aaron Tan.
CS1101: Programming Methodology
CS1020 Data Structures and Algorithms I Lecture Note #14
CSCE 1030 Computer Science 1 First Day. Course Dr. Ryan Garlick Office: Research Park F201 B –Inside the Computer Science department.
CS 139 – Algorithm Development MS. NANCY HARRIS LECTURER, DEPARTMENT OF COMPUTER SCIENCE.
Object Oriented Programming (OOP) LAB # 1 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal.
1.Reading from Keyboard 2.Main programs 3.Responsibilities 1 CS12230 Introduction to Programming Lecture 2or3-Other things.
1 Class 1 Lecture Topic Concepts, Definitions and Examples.
COMP1927 Course Introduction 16x1
Team 7-1 Science, 2 nd Semester Review of some basic policies and procedures.
Welcome to Human Behavior and the Social Environment Dawn Burgess, Ed. D.
Written by: Dr. JJ Shepherd
WEEK 1 Class Activities.
Data Structures and Algorithms in Java AlaaEddin 2012.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 9: Arrays; Revision Session.
Mr H Kandjimi 2016/01/03Mr Kandjimi1 Week 3 –Modularity in C++
Introduction to Programming
CS1010 Programming Methodology
Subroutines Idea: useful code can be saved and re-used, with different data values Example: Our function to find the largest element of an array might.
Welcome to CS 1301! Principles of Programming I.
SE-1021 Software Development 2
CMPE212 – Reminders Assignment 3 due next Friday.
Presentation transcript:

Welcome to CS1102 sem1 08/09 Notes: All of my PowerPoint slides will be uploaded to my website after my last tutorial class every week. 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. 1

About Me Name: Steven Halim – Indonesian Chinese 5 th year (err…) PhD 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: – For extra consultation outside this classroom: – Timing: preferably Thursday, 1-2pm (before T4) or 5-6pm (after T6) – Venue: TA Office: COM (just around the corner, call me from outside) – If you feel that you need help, try to get help as early as possible! 2

About You No time for full introduction… Let’s just do some quick survey – Nationality: Indonesian/Singaporean/Malaysian/Chinese/Vietnamese/Philippines/Indian/ Bangladeshi/Pakistani? Others? – Faculty: COM/CPE/Science? Others? – Origin: Poly/JC/High school in your home country? Others? 3

About This Tutorial (1) Why you should attend this tutorial? – Tutorial attendance and participation: 5% (PE: 20%  15%) – 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, ~ questions to grab – You can be kiasu for today’s tutorial too, 5 questions to grab – me say e.g. “Steven, I want to do T2, – I will confirm your bid based on First-Come-First-Serve basis. – At the end of the day, everyone gets at least one chance. – 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! 4

About This Tutorial (2) What are we going to each tutorial? – Review Past Lectures (10-15 minutes) – Discuss Tutorial Questions (15-35 minutes) Student presentations, according to the assignments – >> Target: finish in 50 minutes… << – 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 5

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 “Algorithms” – Not an easy module – No guarantee that you will understand the materials after my class – But let’s try our best … – Also, read this story later 6

Tutorial 1 Java OO Programming 7

Very Quick Review Problem Solving and Software Engineering – These stuffs will going to be revisited in CS2103! Java Revision – Too many too revise… >.< 127 slides++ in Lecture 1 – However, make sure that you are familiar with all these: 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: definition+usage

Q2 – Spiral Output (1) n is a perfect square if n = i*i; i = sqrt(n); i < n; i  odd integer! – This problem is not well defined for n = 2 2, 4 2, 6 2, etc… Try to solve this algorithm using “pseudo code” – Actual Java code is fine, but perhaps quite complex “Easiest” solution (other suggestions are welcomed): – Use 2-D array of integers of size i*i, where i 2 = 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 direction): You just need to change the algorithm to “check your right side”… The actual Java implementation may require recursion – 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. – Your task: design these classes – Sentence Describe a sentence using “private instance attribute” 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 “NotSentenceException” 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 6)

Q4 – Swapping (3) So what should you to do to make a and b swap values? – 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 = “ + b); }

Q5 – Base and Derived (1) 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 + “ “ + d.dPrivate); } } Private are private! Public are public! Only “protected” needs special considerations!

That’s All for Today See you next week for an even more exciting topics: – Abstract Data Types (ADT) – Using Formula 1 as background story…