![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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/1.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/2.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/3.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/4.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/5.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/6.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/7.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/8.jpg)
Contact information
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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/9.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/10.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/11.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/12.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/13.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/14.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/15.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/16.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/17.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/18.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/19.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/20.jpg)
/*** 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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/21.jpg)
/*** 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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/22.jpg)
/*** 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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/23.jpg)
/*** 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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/24.jpg)
/*** 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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/25.jpg)
/*** 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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/26.jpg)
/*** 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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/27.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/28.jpg)
/*** 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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/29.jpg)
/*** 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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/30.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/31.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/32.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/33.jpg)
/*** 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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/34.jpg)
/*** 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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/35.jpg)
/*** 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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/36.jpg)
/*** 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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/37.jpg)
/*** 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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/38.jpg)
/*** 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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/39.jpg)
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](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697bfe21a28abf838cb483f/html5/thumbnails/40.jpg)
Questions?