COMPSCI 172 – Introduction to Objected-Oriented programming in Java
-
Upload
wang-mcdonald -
Category
Documents
-
view
35 -
download
0
description
Transcript of COMPSCI 172 – Introduction to Objected-Oriented programming in Java
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
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
• Bachelor of Science from Hanoi University of Technology (86-91)
• Master of Computer Science from UW-Milwaukee (96-99)
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
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 ofJava 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)
/*** 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
/*** 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");
/*** 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
/*** 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");
/*** 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
/*** 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");
/*** 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
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).
/*** 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)
/*** 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)
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
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.Professor A
getStudentEarnedCredits()StudentSteven
50
/*** 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
/*** 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; // ….
/*** 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
/*** 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
/*** 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):");
/*** 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
Inheritance
Student
Graduate student
Undergraduatestudent
Masters DoctoralLaw/
MedicineCommuting Resident
Questions?