L14 - CompSci 101 - Lecture 14 1 Computer Science 1 1 SS C...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CompSci 101 - Lecture 14 1 Computer Science 1 1 SS C Lecture 14 Contents Java is an object oriented programming language Representing real world objects in programs Structure of a class deFnition Instance variables Constructors Instance methods Coursebook: pages 13 2 Java is Object Oriented The world is made up of real world objects e.g. students, dogs, cars, cats, books. Objects are the things our programs deal with. 3 State and behaviour Every real world object has: state- information stored about an object. behaviour- functionality of the object i.e what can you do with that object. and 4 Example 1 - state and behaviour Consider a system managing university students. A student object has: id, name, age, contact number, address, stage, completed courses, current courses, faculty, add a new course, change contact number, change address, set faculty, state behaviour 5 Example 2 - state and behaviour Consider a system managing university courses. A course object has: id, name, faculty, list of current students, stage number, list of lecture times, semester offered, campus, test date, exam date add/remove student to course, change test date, change lecture time, set semester offered state behaviour 6 Ex01 - state and behaviour Consider a system managing university lecture rooms. A lecture room object has: State Behaviour CompSci 101 - Lecture 14 2 7 Software objects - state and behaviour A software object stores its state in one or more variables methods A software object implements its behaviour with 8 Software objects - state and behaviour Every object is a bundle of variables and related methods. Note: The term, , is the same as the term, . object instance 9 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Storing object information so far public class ProgramL14 { public void start() { } } String s1Name = "Ann Li"; String s1ResultCourse1 = "A"; String S1Course1 = "CS111"; String info = s1Name + " " + s1ID + " " + s1YearEnr + " " + s1Course1 + " " + s1Course1Result + ; String S1ResultCourse2 = "A+"; String S1Course2 = "CS101"; System.out.println(info); String s1Degree = "BSc"; int s1ID = 8564221; int s1YearEnr = 2009; int s1CoursesStage1 = 2; 10 1 2 3 4 5 6 7 8 9 10 11 Java objects What we would like to be able to do public class ProgramL14 { public void start() { } } Student s1 = new Student(8564221,"Ann Li","BSc", 2009); s1.addCourse("CS", 111, 0, 2009); s1.addCourse("CS", 101, 1, 2009); String info = s1.getListOfCourses(2009); s1.addResult("CS", 101, "A+"); s1.addCourse("Maths", 108, 1, 2009); System.out.println(info); 1 2 3 4 5 6 11 Ex02 - String objects In programs you have used String objects. What is the state and behaviour of a String object?...
View Full Document

This note was uploaded on 03/01/2012 for the course COMPSCI 101 taught by Professor Adrianaferraro during the Summer '12 term at Auckland.

Page1 / 7

L14 - CompSci 101 - Lecture 14 1 Computer Science 1 1 SS C...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online