1 / 40

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 .

Télécharger la présentation

COMPSCI 172 – Introduction to Objected-Oriented programming in Java

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 115

  2. 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

  3. 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

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

  5. 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)

  6. 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

  7. Self-Introduction • Teaching philosophy: • Interactive • Adaptive • Pro-active • Collaborative • Other hobbies (non-academic related) • Movies • College Basketball • Family activities

  8. Contact information nguyenh@uww.edu Baker Hall 324 Office Hours: 2:15-4:15pm, MWF, or by appointment 262 472 5170

  9. Course detail - Topics Object-oriented design and implement using Java Understanding of algorithm, objects, classes Fundamentals of Java language & program Specific Applications

  10. Course detail - Evaluation

  11. 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!!!

  12. Questions?

  13. Introduction to OO Programming and Java

  14. Lesson plan • History & Novelty of Java • Class & Objects

  15. 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)

  16. 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.

  17. 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

  18. 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

  19. 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)

  20. /** * 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 borrowed int loanPeriod; // represents the number of years of the loan ….. DecimalFormat df = new DecimalFormat("0.00"); Multi-line comment Comments Single-line comment

  21. /** * 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");

  22. /** * 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"); Import statement

  23. /** * 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");

  24. /** * 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"); Class Declaration

  25. /** * 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");

  26. /** * 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 borrowed int loanPeriod; // represents the number of years of the loan ….. DecimalFormat df = new DecimalFormat("0.00"); Class Declaration

  27. 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).

  28. /** * 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"); Behaviors (Main Method)

  29. /** * 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 borrowed int loanPeriod; // represents the number of years of the loan ….. DecimalFormat df = new DecimalFormat("0.00"); Attributes (Fields)

  30. Class and Objects (Example) Student Name ID Credit earned Class Student_Steven Name=“Steven” Id=“001” Credit earned=50 Student_Emily Name=“Emily” Id=“002” Credit earned=100 Objects

  31. 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 .

  32. 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 StudentSteven 50

  33. /** * 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"); Object Instantiation

  34. /** * 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; // ….

  35. /** * 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 String inputStr; ….. inputStr = JOptionPane.showInputDialog(null,"Loan Amount (dollars.cents):"); Object Interactions

  36. /** * 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 String inputStr; ….. inputStr = JOptionPane.showInputDialog(null,"Loan Amount (dollars.cents):"); Variable Declaration

  37. /** * 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):");

  38. /** * 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; Assign Statement Expressions

  39. Inheritance Student Graduate student Undergraduate student Masters Doctoral Law/ Medicine Commuting Resident

  40. Questions?

More Related