Week 1 slides
Download
Report
Transcript Week 1 slides
COMPSCI 172 –
Introduction to ObjectedOriented programming in Java
Class hour:
12:05-12:55 pm MWF (section 1).
1:10-2:00 pm MWF (section 2)
McGraw Room 115
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
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
Introduction
Tell me about yourself and what you expect
to get out from this course
Self-Introduction
• Recently graduated from the
University of Connecticut (05
Class), Ph.D in Computer
Science and Engineering
• Master of Computer Science
from UW-Milwaukee (96-99)
• Bachelor of Science from
Hanoi University of
Technology (86-91)
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
Self-Introduction
• Teaching philosophy:
– Interactive
– Adaptive
– Pro-active
– Collaborative
• Other hobbies (non-academic related)
– Movies
– College Basketball
– Family activities
Contact information
[email protected]
Baker Hall 324
Office Hours: 2:15-4:15pm,
MWF, or by appointment
262 472 5170
Course detail - Topics
Object-oriented
design and implement
using Java
Understanding
of algorithm,
objects, classes
Fundamentals of
Java language
& program
Specific
Applications
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
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!!!
Questions?
Introduction to OO
Programming and Java
Lesson plan
• History & Novelty of Java
• Class & Objects
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)
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.
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
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
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)
Multi-line comment
/**
Comments
* Sample program …
**/
import javax.swing.*; /* Multiple comments */
import java.text.*;
public class LoanCalculator{
Single-line comment
public static void main(String[] args) {
final int MONTHS_IN_YEAR = 12;
double loanAmount; // represents the amount being borrowed
int loanPeriod; // represents the number of years of the loan
…..
DecimalFormat df = new DecimalFormat("0.00");
/**
* 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 borrowed
int loanPeriod; // represents the number of years of the loan
…..
DecimalFormat df = new DecimalFormat("0.00");
/**
* Sample program …
**/
import javax.swing.*;
import java.text.*;
Import
statement
public class LoanCalculator{
public static void main(String[] args) {
final int MONTHS_IN_YEAR = 12;
double loanAmount; // represents the amount being borrowed
int loanPeriod; // represents the number of years of the loan
…..
DecimalFormat df = new DecimalFormat("0.00");
/**
* 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 borrowed
int loanPeriod; // represents the number of years of the loan
…..
DecimalFormat df = new DecimalFormat("0.00");
/**
* Sample program …
**/
Class
Declaration
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 borrowed
int loanPeriod; // represents the number of years of the loan
…..
DecimalFormat df = new DecimalFormat("0.00");
/**
* 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 borrowed
int loanPeriod; // represents the number of years of the loan
…..
DecimalFormat df = new DecimalFormat("0.00");
/**
* Sample program …
**/
Class
Declaration
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 borrowed
int loanPeriod; // represents the number of years of the loan
…..
DecimalFormat df = new DecimalFormat("0.00");
Class and Objects
A class definition provides a
description of a typical object within
that class.
student, faculty, person
An individual object is an instance
of a class.
Definition of behavior (methods) and
attributes (fields).
/**
* Sample program …
**/
import javax.swing.*;
import java.text.*;
Behaviors
(Main
Method)
public class LoanCalculator{
public static void main(String[] args) {
final int MONTHS_IN_YEAR = 12;
double loanAmount; // represents the amount being borrowed
int loanPeriod; // represents the number of years of the loan
…..
DecimalFormat df = new DecimalFormat("0.00");
/**
* Sample program …
**/
Attributes
(Fields)
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 borrowed
int loanPeriod; // represents the number of years of the loan
…..
DecimalFormat df = new DecimalFormat("0.00");
Class and Objects (Example)
Class
Objects
Student
Name
ID
Credit earned
Student_Steven
Name=“Steven”
Id=“001”
Credit earned=50
Student_Emily
Name=“Emily”
Id=“002”
Credit earned=100
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
.
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.
getStudentEarnedCredits()
Professor A
50
StudentSteven
/**
* Sample program …
**/
import javax.swing.*;
import java.text.*;
Object
Instantiation
public class LoanCalculator{
public static void main(String[] args) {
final int MONTHS_IN_YEAR = 12;
double loanAmount; // represents the amount being borrowed
int loanPeriod; // represents the number of years of the loan
…..
DecimalFormat df = new DecimalFormat("0.00");
/**
* 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 borrowed
int loanPeriod; // represents the number of years of the loan
…..
DecimalFormat df; // ….
/**
* Sample program …
**/
import javax.swing.*;
import java.text.*;
Object
Interactions
public class LoanCalculator{
public static void main(String[] args) {
final int MONTHS_IN_YEAR = 12;
double loanAmount; // represents the amount being borrowed
int loanPeriod; // represents the number of years of the loan
String inputStr;
…..
inputStr = JOptionPane.showInputDialog(null,"Loan Amount
(dollars.cents):");
/**
* Sample program …
**/
import javax.swing.*;
import java.text.*;
Variable
Declaration
public class LoanCalculator{
public static void main(String[] args) {
final int MONTHS_IN_YEAR = 12;
double loanAmount; // represents the amount being borrowed
int loanPeriod; // represents the number of years of the loan
String inputStr;
…..
inputStr = JOptionPane.showInputDialog(null,"Loan Amount
(dollars.cents):");
/**
* 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 loan
String inputStr;
…..
inputStr = JOptionPane.showInputDialog(null,"Loan Amount
(dollars.cents):");
/**
* Sample program …
**/
import javax.swing.*;
import java.text.*;
Assign
Statement
public class LoanCalculator{
public static void main(String[] args) {
monthlyInterestRate = annualInterestRate / MONTHS_IN_YEAR/ 100;
numberOfPayments = loanPeriod * MONTHS_IN_YEAR;
monthlyPayment = (loanAmount * monthlyInterestRate)/(1Math.pow(1/(1+monthlyInterestRate),numberOfPayments));
totalPayment = monthlyPayment * numberOfPayments;
Expressions
Inheritance
Student
Undergraduate
student
Graduate
student
Masters
Doctoral
Law/
Medicine
Commuting
Resident
Questions?