COMPUTER 2430 Object Oriented Programming and Data Structures I

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

1 Todays Objectives Announcements Homework #1 is due next week Return Quiz 1 – answers are posted on the Yahoo discussion page site Basic Java Programming.
DATA STRUCTURES Lecture: Interfaces Slides adapted from Prof. Steven Roehrig.
Chapter 1 Object-Oriented Concepts. A class consists of variables called fields together with functions called methods that act on those fields.
Class Scope class Student { private: string id; string firstName, lastName; float gpa; public: void Read() { cin >> id >> firstName >> lastName >> gpa;
Student Data Score First Name Last Name ID GPA DOB Phone... How to store student data in our programs? 1.
Chapter 3 DATA: TYPES, CLASSES, AND OBJECTS. Chapter 3 Data Abstraction Abstract data types allow you to work with data without concern for how the data.
Object Oriented Programming in Java. Object Oriented Programming Concepts in Java Object oriented Programming is a paradigm or organizing principle for.
Prepared by Dr. Inayatullah Shah1 Data Structures CSC212.
1 Data Structures CSC Data Types & Data Structures Applications/programs read, store and operate on data. Finally output results. What is data?
1 Data Structures: Introduction CSC Data Types & Data Structures Applications/programs read data, store data temporarily, process it and finally.
TA: Nouf Al-Harbi NoufNaief.net :::
Introduction to Java Programming Language May 2015 Kyung Eun Park COSC Introduction to Computer Science II.
CSC3170 Introduction to Database Systems
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Viswanathan Inheritance and Polymorphism Course Lecture Slides 2 nd June 2010 “ We are.
CS 2430 Day 9. Announcements Quiz on Friday, 9/28 Prog1: see , see me as soon as possible with questions/concerns Prog2: do not add any public methods.
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
Introduction to Java Classes and Objects. What is a class A class is description of a structure that contains both data and methods – Describes a set.
JAVA Classes Review. Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Classes Structured Programming 256 Chapter 8 Classes - Part I OOP & Class Object Terminology File Management.
Java - Classes JPatterson. What is a class? public class _Alpha { public static void main(String [] args) { } You have been using classes all year – you.
Class Student class Student { private: string id; string firstName, lastName; float gpa; public: void Read() void Write() string getGPA() void setGPA(
CS 2430 Day 9. Announcements Quiz 2.1 this Friday Program 2 due this Friday at 3pm (grace date Sunday at 10pm)
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Classes and Objects (contd.) Course Lecture Slides 19 May 2010.
Class Method Read class Student { private: string id; string firstName, lastName; float gpa; public: // Will the method change any data members? // Yes!
CS 116 Lecture 1 John Korah Contains content provided by George Koutsogiannakis & Matt Bauer.
Midterm Review Tami Meredith. Primitive Data Types byte, short, int, long Values without a decimal point,..., -1, 0, 1, 2,... float, double Values with.
CSC 243 – Java Programming, Spring, 2014 Week 4, Interfaces, Derived Classes, and Abstract Classes.
CSC 243 – Java Programming, Fall, 2008 Tuesday, September 30, end of week 5, Interfaces, Derived Classes, and Abstract Classes.
Nested Structures struct TDate { int year, month, day; }; struct StudentType { string id, firstName, lastName; float gpa; TDate DOB; }; struct SectionType.
(Dreaded) Quiz 2 Next Monday.
COMPUTER 2430 Object Oriented Programming and Data Structures I
Object-Oriented Concepts
CSC111 Quick Revision.
Object Oriented Programming
CS0007: Introduction to Computer Programming
COMPUTER 2430 Object Oriented Programming and Data Structures I
Java: Base Types All information has a type or class designation
Yanal Alahmad Java Workshop Yanal Alahmad
Prepared by Dr. Inayatullah Shah
COMPUTER 2430 Object Oriented Programming and Data Structures I
Syntax & Semantics UML - Java
Lecture 17: Polymorphism (Part II)
COMPUTER 2430 Object Oriented Programming and Data Structures I
CS 1430: Programming in C++.
Student Data Score First Name Last Name ID GPA DOB Phone ...
Introduction to Computer Programming
CS 1430: Programming in C++.
CS 1430: Programming in C++.
null, true, and false are also reserved.
COMPUTER 2430 Object Oriented Programming and Data Structures I
Introduction to Java Programming
COMPUTER 2430 Object Oriented Programming and Data Structures I
COMPUTER 2430 Object Oriented Programming and Data Structures I
COMPUTER 2430 Object Oriented Programming and Data Structures I
Know for Quiz Everything through Last Week and Lab 7
Introduction to Objects
COMPUTER 2430 Object Oriented Programming and Data Structures I
Data Structures: Introduction
CS 2430 Object Oriented Programming and Data Structures I
Lecture 18: Polymorphism (Part II)
COMPUTER 2430 Object Oriented Programming and Data Structures I
Object Oriented Programming.
Data Structures: Abstract Data Types (ADTs)
Data Structures: Introduction
Control Structure.
មជ្ឈមណ្ឌលកូរ៉េ សហ្វវែរ អេច អ ឌី
CIS 110: Introduction to computer programming
Presentation transcript:

COMPUTER 2430 Object Oriented Programming and Data Structures I Using NetBeans for class Object methods toString and equals (no programs on inheritance now) 20 minutes for Quiz 1

Java String // Data type String is a class! // All class names begin with a capital char String firstName, lastName, str; // Get a String object firstName = new String("first"); str = "First"; // same as // str = new String("First"); We do not need this: import java.lang.*; // Not just for String

Operator + String str = "First"; int x = 10; // str = str + "appends to a string"; str += "appends to a string"; // "Firstappends to a string" str += " need a space here“; // "Firstappends to a string need a space here" str = str + ',' + x; // "Firstappends to a string need a space here,10“ // str += ',' + x; might be different!

Method length() public class String { . . . /** Returns the number of chars in "this" string Sample code: int count = str.length(); */ public int length() } Both are instance methods

Method equals() public class String { . . . /** Returns true when "this" string has the same sequence of chars as string s false otherwise Sample code: if ( str1.equals(str2) ) */ public boolean equals( String s ) } Both are instance methods

Example String str1, str2; Scanner sc = new Scanner( System.in ); str1 = new String("first"); str2 = sc.next(); // next string (token) if (str1.equals(str2)) System.out.println("str1 is the same as str2."); else System.out.println("str1 is not the same as str2."); System.out.println("str1 has " + str1.length() + " chars.");

Java String str1 = new String("first"); str2 = sc.next(); // input: first if (str1.equals(str2)) System.out.println("equal."); else System.out.println("not equal."); if (str1 == str2) System.out.println("Same string."); System.out.println("Not the same string.");

ADT: Student Data Name, Address, Phone, Email DOB GPA . . . Operations Set/Get name

ADT: Professor Data Name, Address, Phone, Email DOB Tenured . . . Operations Set/Get name

Features of OOP Abstraction Encapsulation Data Hiding Inheritance Polymorphism

ADT: Person Data Operations Name, Address, Phone, Email DOB . . . Set/Get name

public class Person { private String name, address, phone, email; private Date dob; . . . public boolean setName (String s) boolean valid = false; if (s.length() > 1) name = s; valid = true; } return valid; public String getName() return name; ...

/** Will inherit all members from class Person, including name and the two methods on name public boolean setName (String s) public String getName() */ public class Student extends Person { private float gpa; public boolean setGPA (float value) public float getGPA() . . . }

/** Will inherit all members from class Person, including name and the two methods on name public boolean setName (String s) public String getName() */ public class Professor extends Person { private boolean tenured; public boolean applyGrant (String grantName) public void teachCourse (String courseName) . . . }

public class CS2430Sx { public static void main(String[] args) Student std = new Student(); std.setName("Frank"); System.out.println("Student: " + std.getName()); Professor prof = new Professor(); prof.setName("Qi"); System.out.println("Professor: " + prof.getName()); }

Features of OOP Abstraction Encapsulation Data Hiding Inheritance Polymorphism

Prog 1 Due 10 pm, Friday, September 14 -2 by 10 pm, Saturday, September 15 -5 by 10 pm, Monday, September 17 No credit after 10 pm, September 17 Still have to complete the program!

Lab 2 Five (5) points Due 10 pm, Friday, September 21

Last Day to Drop Classes

Quiz 1 30 Minutes Close book Close notes Close computer