Top Banner
COMPSCI 172 Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room 115
40

COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

Jan 18, 2016

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

COMPSCI 172 – Introduction to Objected-Oriented programming in Java

Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2)McGraw Room 115

Page 2: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

Course Objectives

• Given a description of a simple problem, formulate algorithms following object-oriented design concepts to solve this problem

• Given a description of a simple problem, implement

the solution in Java which uses class construction, interface, methods, messages passing, file processing, and simple Graphical User Interface

Page 3: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

Textbook/Technology requirement

Textbook:An Introduction to Object-Oriented Programming with Java (third edition). C. Thomas Wu. 2004. McGraw-Hill Publishing

Software:• J2SE Software Development Kit (SDK):

http://java.sun.com/j2se/1.4.2/download.html • Textpad: download at http://

www.textpad.com/download/index.html#downloads

Page 4: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

Introduction

Tell me about yourself and what you expect to get out from this course

Page 5: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

Self-Introduction• Recently graduated from the

University of Connecticut (05 Class), Ph.D in Computer Science and Engineering

• Bachelor of Science from Hanoi University of Technology (86-91)

• Master of Computer Science from UW-Milwaukee (96-99)

Page 6: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

Self-Introduction

• Research Experience:– User Modeling, Information Retrieval,

Decision Theory, Collaborative Filtering, Human Factors

• Teaching Experience:– CS172, 181, 271 at UWW– Introduction courses at UOP and Devry– TA for Computer Architecture, OO Design,

Compiler, Artificial Intelligence

Page 7: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

Self-Introduction

• Teaching philosophy:– Interactive– Adaptive– Pro-active– Collaborative

• Other hobbies (non-academic related)– Movies– College Basketball– Family activities

Page 8: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

Contact information

[email protected]

Baker Hall 324

Office Hours: 2:15-4:15pm, MWF, or by appointment

262 472 5170

Page 9: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

Course detail - Topics

Object-oriented design and implement

using Java

Understanding of algorithm,

objects, classes

Fundamentals ofJava language

& program

Specific Applications

Page 10: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

Course detail - Evaluation

GRADABLE POINTS

Homework 1 100

Homework 2 100

Exam 1 150

Exam 2 150

Project 1 100

Project 2 100

Project 3 100

Final Exam 200

Total 1000

Page 11: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

What does it take to success

• Practice, practice, practice!!! (Programming, reading, doing practice exercises)

• Prior programming skills help

• Participate in class discussion and group discussion

• Thinking, thinking, thinking!!!

Page 12: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

Questions?

Page 13: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

Introduction to OO Programming and Java

Page 14: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

Lesson plan

• History & Novelty of Java

• Class & Objects

Page 15: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

History

• High-level programming language • Low level programming language: CPU instruction sets.• High level programming languages:

• Compiled (C/C++, Pascal) and interpreted language (Basic)• Procedural (Pascal, C) and object oriented language (C++, Java)

Page 16: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

Java’s Ancestry

• Oak: a reimplementation of C++ in the early 1990s by James Gosling.– Intended for intelligent consumer devices.

• Oak became Java in 1995.– Portability and Security of primary concern.– Eminently suitable for Web applets.– Also a powerful language in its own right.

Page 17: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

What is news with Java?

• Platform-independent (portability)– The JVM is an imaginary CPU with

bytecode instructions. Java programs are translated to bytecodes by the Java compiler

• Object-oriented: code reusable

• Lost of resources and tools

Page 18: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

What is news with Java

Inheritance:

capability of a class to use the properties and methods of another class while adding its own functionality

Polymorphism: capability of an action or method

to do different things based on the object that it is acting upon

Page 19: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

Practice (LoanCalculator)

• Type in TextPad and save the file as LoanCalculator.java

• Compile in TextPad by:– Tool -> Compile Java

• Run this application by– Tool -> Run Java Application

(First save LoanCalculator.java file to C:\Document and Setting, under your directory, compile and run it)

Page 20: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

/*** Sample program …**/import javax.swing.*; /* Multiple comments */import java.text.*;

public class LoanCalculator{

public static void main(String[] args) {

final int MONTHS_IN_YEAR = 12;

double loanAmount; // represents the amount being borrowedint loanPeriod; // represents the number of years of the loan…..DecimalFormat df = new DecimalFormat("0.00");

Comments

Multi-line comment

Single-line comment

Page 21: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

/*** Sample program …**/import javax.swing.*;import java.text.*;

public class LoanCalculator{

public static void main(String[] args) {/* Add a multi-line comment here */final int MONTHS_IN_YEAR = 12; // Add your comment here

double loanAmount; // represents the amount being borrowedint loanPeriod; // represents the number of years of the loan…..DecimalFormat df = new DecimalFormat("0.00");

Page 22: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

/*** Sample program …**/import javax.swing.*;import java.text.*;

public class LoanCalculator{

public static void main(String[] args) {

final int MONTHS_IN_YEAR = 12;

double loanAmount; // represents the amount being borrowedint loanPeriod; // represents the number of years of the loan…..DecimalFormat df = new DecimalFormat("0.00");

Import statement

Page 23: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

/*** Sample program …**/// import javax.swing.*;import java.text.*;

public class LoanCalculator{

public static void main(String[] args) {

final int MONTHS_IN_YEAR = 12;

double loanAmount; // represents the amount being borrowedint loanPeriod; // represents the number of years of the loan…..DecimalFormat df = new DecimalFormat("0.00");

Page 24: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

/*** Sample program …**/import javax.swing.*;import java.text.*;

public class LoanCalculator{

public static void main(String[] args) {

final int MONTHS_IN_YEAR = 12;

double loanAmount; // represents the amount being borrowedint loanPeriod; // represents the number of years of the loan…..DecimalFormat df = new DecimalFormat("0.00");

Class Declaration

Page 25: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

/*** Sample program …**/import javax.swing.*;import java.text.*;

Public class loancalculator{

public static void main(String[] args) {

final int MONTHS_IN_YEAR = 12;

double loanAmount; // represents the amount being borrowedint loanPeriod; // represents the number of years of the loan…..DecimalFormat df = new DecimalFormat("0.00");

Page 26: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

/*** Sample program …**/import javax.swing.*;import java.text.*;

class LoanCalculator{

public static void main(String[] args) {

final int MONTHS_IN_YEAR = 12;

double loanAmount; // represents the amount being borrowedint loanPeriod; // represents the number of years of the loan…..DecimalFormat df = new DecimalFormat("0.00");

Class Declaration

Page 27: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

Class and Objects

A class definition provides a description of a typical object within that class.

student, faculty, personAn individual object is an instance of a class.

Definition of behavior (methods) and attributes (fields).

Page 28: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

/*** Sample program …**/import javax.swing.*;import java.text.*;

public class LoanCalculator{

public static void main(String[] args) {

final int MONTHS_IN_YEAR = 12;

double loanAmount; // represents the amount being borrowedint loanPeriod; // represents the number of years of the loan…..DecimalFormat df = new DecimalFormat("0.00");

Behaviors(Main

Method)

Page 29: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

/*** Sample program …**/import javax.swing.*;import java.text.*;

public class LoanCalculator{private final int MONTHS_IN_YEAR = 12;

public static void main(String[] args) {

double loanAmount; // represents the amount being borrowedint loanPeriod; // represents the number of years of the loan…..DecimalFormat df = new DecimalFormat("0.00");

Attributes(Fields)

Page 30: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

Class and Objects (Example)

Student_StevenName=“Steven”

Id=“001”Credit earned=50

Student_EmilyName=“Emily”

Id=“002”Credit earned=100

Objects

StudentName

IDCredit earned

Class

Page 31: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

Class and Instances

• Class definition is like a blueprint or template.– Color, size, pattern might vary, but

instances of the same class come from the same mold

.

Page 32: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

Object Interactions• Communication between people:

Information: “I am going to a party.”

Question: “What is the time?”Order/Request: “Please buy

me some gum.”

• Objects communicate in similar ways.Professor A

getStudentEarnedCredits()StudentSteven

50

Page 33: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

/*** Sample program …**/import javax.swing.*;import java.text.*;

public class LoanCalculator{

public static void main(String[] args) {

final int MONTHS_IN_YEAR = 12;

double loanAmount; // represents the amount being borrowedint loanPeriod; // represents the number of years of the loan…..DecimalFormat df = new DecimalFormat("0.00");

Object Instantiation

Page 34: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

/*** Sample program …**/import javax.swing.*;import java.text.*;

public class LoanCalculator{

public static void main(String[] args) {

final int MONTHS_IN_YEAR = 12;

double loanAmount; // represents the amount being borrowedint loanPeriod; // represents the number of years of the loan…..DecimalFormat df; // ….

Page 35: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

/*** Sample program …**/import javax.swing.*;import java.text.*;

public class LoanCalculator{

public static void main(String[] args) {

final int MONTHS_IN_YEAR = 12;

double loanAmount; // represents the amount being borrowedint loanPeriod; // represents the number of years of the loanString inputStr;…..inputStr = JOptionPane.showInputDialog(null,"Loan Amount

(dollars.cents):");

Object Interactions

Page 36: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

/*** Sample program …**/import javax.swing.*;import java.text.*;

public class LoanCalculator{

public static void main(String[] args) {

final int MONTHS_IN_YEAR = 12;

double loanAmount; // represents the amount being borrowedint loanPeriod; // represents the number of years of the loanString inputStr;…..inputStr = JOptionPane.showInputDialog(null,"Loan Amount

(dollars.cents):");

Variable Declaration

Page 37: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

/*** Sample program …**/import javax.swing.*;import java.text.*;

public class LoanCalculator{

public static void main(String[] args) {

final int MONTHS_IN_YEAR = 12;

// double loanAmount; // represents the amount being ..int loanPeriod; // represents the number of years of the loanString inputStr;…..inputStr = JOptionPane.showInputDialog(null,"Loan Amount

(dollars.cents):");

Page 38: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

/*** Sample program …**/import javax.swing.*;import java.text.*;

public class LoanCalculator{

public static void main(String[] args) {

monthlyInterestRate = annualInterestRate / MONTHS_IN_YEAR/ 100;numberOfPayments = loanPeriod * MONTHS_IN_YEAR;monthlyPayment = (loanAmount * monthlyInterestRate)/(1-

Math.pow(1/(1+monthlyInterestRate),numberOfPayments));

totalPayment = monthlyPayment * numberOfPayments;

AssignStatement

Expressions

Page 39: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

Inheritance

Student

Graduate student

Undergraduatestudent

Masters DoctoralLaw/

MedicineCommuting Resident

Page 40: COMPSCI 172 – Introduction to Objected- Oriented programming in Java Class hour: 12:05-12:55 pm MWF (section 1). 1:10-2:00 pm MWF (section 2) McGraw Room.

Questions?