Ist.psu.edu School of Information Sciences and Technology IST 311 – Object-Oriented Design & Software Steven Haynes IST 311 – Class 4 19 January 2006

Slides:



Advertisements
Similar presentations
Ist.psu.edu School of Information Sciences and Technology IST 311 – Object-Oriented Design & Software Steven Haynes IST 311 – Class 1 10 January 2005
Advertisements

Chapter 41 Variables and JSP Control Structures JavaServer Pages By Xue Bai.
5-1 Flow of Control Recitation-01/25/2008  CS 180  Department of Computer Science  Purdue University.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 2 “ Data and Expressions”
Loops – While, Do, For Repetition Statements Introduction to Arrays
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Chapter 2 - Java Programming Fundamentals1 Chapter 2 Java Programming Fundamentals.
COMP1170 Midterm Preparation (March 17 th 2009) Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education.
CSci 142 Data and Expressions. 2  Topics  Strings  Primitive data types  Using variables and constants  Expressions and operator precedence  Data.
VB .NET Programming Fundamentals
CONTROL STATEMENTS Lakhbir Singh(Lect.IT) S.R.S.G.P.C.G. Ludhiana.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
High-Level Programming Languages: C++
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Programming in Java Unit 4. Learning outcome:  LO2: Be able to design Java solutions  LO3: Be able to implement Java solutions Assessment criteria:
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Chapter 7 Additional Control Structures. Chapter 7 Topics l Switch Statement for Multi-Way Branching l Do-While Statement for Looping l For Statement.
CompSci 100E 2.1 Java Basics - Expressions  Literals  A literal is a constant value also called a self-defining term  Possibilities: o Object: null,
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Introduction to Java Java Translation Program Structure
Ist.psu.edu School of Information Sciences and Technology IST 311 – Object-Oriented Design & Software Steven Haynes IST 311 – Class 7 17 January 2006
Chapter 10 Defining Classes. The Internal Structure of Classes and Objects Object – collection of data and operations, in which the data can be accessed.
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
CSC 212 Object-Oriented Programming and Java Part 2.
1 Program Development  The creation of software involves four basic activities: establishing the requirements creating a design implementing the code.
CSM-Java Programming-I Spring,2005 Fundamental Data Types Lesson - 2.
Chapter 3: Introducing the UML
1 b Boolean expressions b truth tables b conditional operator b switch statement b repetition statements: whilewhile do/whiledo/while forfor Lecture 3.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 8 Java Fundamentals Control Structures Fri.
1 Predefined Classes and Objects Chapter 3. 2 Objectives You will be able to:  Use predefined classes available in the Java System Library in your own.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Flow of Control Joe McCarthy CSS 161: Fundamentals of Computing1.
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
CISC105 – General Computer Science Class 4 – 06/14/2006.
Control structures in C by Dr P.Padmanabham Professor (CSE)&Director Bharat Institute of Engineering &Technology Hyderabad Mobile
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
Chapter 2: Data and Expressions. Variable Declaration In Java when you declare a variable, you must also declare the type of information it will hold.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
IST 311 – Object-Oriented Design & Software
Information and Computer Sciences University of Hawaii, Manoa
Java Primer 1: Types, Classes and Operators
Control Statements: Part 2
Java Programming: From Problem Analysis to Program Design, 4e
MSIS 655 Advanced Business Applications Programming
Chapter 3 Introduction to Classes, Objects Methods and Strings
Chapter 8 JavaScript: Control Statements, Part 2
Chapter 2: Basic Elements of Java
Chapter 7 Additional Control Structures
MSIS 655 Advanced Business Applications Programming
PHP.
Python Primer 1: Types and Operators
Chapter 2 Programming Basics.
Object Oriented Programming in java
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Introduction to Computer Science
In this class, we will cover:
Problem 1 Given n, calculate 2n
Presentation transcript:

ist.psu.edu School of Information Sciences and Technology IST 311 – Object-Oriented Design & Software Steven Haynes IST 311 – Class 4 19 January 2006

ist.psu.edu School of Information Sciences and Technology Mid-Term Deliverables Use Case diagrams –Derived from scenarios Class diagram –Conceptual Sequence diagrams TBD –Need use cases first User Interface Design –Need use cases first Due Thursday, March 3 rd (Thursday before break)

ist.psu.edu School of Information Sciences and Technology Design Representations Why learn the UML? What is the purpose of design representation languages and techniques?

ist.psu.edu School of Information Sciences and Technology Design Representations An aid to design cognition A common language for communicating about a design (specifications) A record of the design process and its outcomes (documentation)

ist.psu.edu School of Information Sciences and Technology UML Diagrams, Part 1. Use Case diagram

ist.psu.edu School of Information Sciences and Technology UML Diagrams Use Case diagram –Identify major services provided by a system to external actors (users and other systems) Establish the boundaries of the system Identify common functionality Identify high-level alternate use scenarios –Capture requirements –Development project planning tasks –Communicate with the customer/user.

ist.psu.edu School of Information Sciences and Technology Use Case Diagram

ist.psu.edu School of Information Sciences and Technology Use Cases Actors Use Cases Include (Uses) Use Cases Extend Use Cases Annotations –Pre-conditions –Post-conditions –Constraints Don’t use actor or use case generalization

ist.psu.edu School of Information Sciences and Technology Guidelines for Use Cases Actors – specific user roles Human actors on left Non-human actors (systems) on right Use Cases – verb-noun phrase e.g., Verify Credit Card Include (uses) link – included use case MUST be completed for the including use case to complete Extend link – extending use case represents a variant of the extended use case

ist.psu.edu School of Information Sciences and Technology Guidelines for Use Cases Use cases model system interactions. Use case granularity THE big problem Use annotations (notes) freely to document your assumptions. Use cases are not data stores Use cases are not data flow diagrams

ist.psu.edu School of Information Sciences and Technology UML Diagrams Class diagram

ist.psu.edu School of Information Sciences and Technology UML Diagrams Class diagram –Identify classes Attributes Operations –Identify class relationships –Identify packages –Describe a system’s static structure

ist.psu.edu School of Information Sciences and Technology Class Diagram

ist.psu.edu School of Information Sciences and Technology UML Diagrams Sequence diagram

ist.psu.edu School of Information Sciences and Technology UML Diagrams Sequence diagram –Describe the sequence of steps required to realize a use case or use case scenario, which represent requirements –Describe interactions between objects/classes –Perspective is time oriented

ist.psu.edu School of Information Sciences and Technology Sequence Diagram

ist.psu.edu School of Information Sciences and Technology UML Diagrams Collaboration diagram

ist.psu.edu School of Information Sciences and Technology UML Diagrams Collaboration diagram –Same as Sequence diagram except… –Perspective is structural or spatial

ist.psu.edu School of Information Sciences and Technology Collaboration Diagram

ist.psu.edu School of Information Sciences and Technology Degree Audit Use Cases & Classes

ist.psu.edu School of Information Sciences and Technology Practice Exploratory Learning! Read Raposa chapters with a Java development environment at hand Experiment with his or your own code fragments to ensure you understand a given point

ist.psu.edu School of Information Sciences and Technology Code Comments, Diagram Annotations Always comment your code Always annotate diagrams Most points are lost on assignments and projects because of clarity issues. Comments and annotations help overcome these problems.

ist.psu.edu School of Information Sciences and Technology Important from Chapters 1-3 Ch. 1 –The JVM –Bytecodes –Classes vs. Objects –.java vs..class files –Command-line arguments –The main method Ch. 2 –Java keywords –Java identifiers –Primitive data types –Declaring, initializing, assigning variables –Java Strings –Reference vs. primitive data –Constants –Operators –Comments Ch. 3 –Java control structures –Boolean operators and logic

ist.psu.edu School of Information Sciences and Technology Assumptions You know what data types are and can select the appropriate type from those available in Java You know what Java keywords are and can find and use them appropriately You can declare, initialize, and use Java variables and constants

ist.psu.edu School of Information Sciences and Technology Assumptions Continued You know what operators are and can use them – Logical: AND (&&), OR (||), EXCLUSIVE-OR (^) and NOT (!) –Arithmetic: Addition (+), Subtraction (-), Multiplication (*), Division (/), Modulus (%) –Increment (e.g., i++, ++i), Decrement (e.g., k--, --k) –Assignment (=, +=, -=, *=, /=, %=) –Relational (==,, =, !=) You know how to use the different Java comment types

ist.psu.edu School of Information Sciences and Technology Classes and Objects What’s the difference?

ist.psu.edu School of Information Sciences and Technology Classes and Objects A class is a blueprint or template for creating objects and defines –An object’s attributes –An object’s behaviors (methods) An object is an instance of a class To create objects we instantiate a class

ist.psu.edu School of Information Sciences and Technology Java Strings A string is a collection of character (char) data. Strings are important data structures in any programming language A java.lang.String object is a sequence of characters plus a collection of methods for manipulating strings. Unlike other Java objects, Strings have certain characteristics in common with the primitive data types. For example, strings can have literals. A String literal is a sequence of zero or more characters contained in double quotes -- for example, “Socrates” and “” (empty string).

ist.psu.edu School of Information Sciences and Technology Java Strings The + symbol is used as a binary concatenation operator for Strings. It has the effect of joining two strings together. Primitive types are automatically promoted to strings when mixed with concatenation operators. The number of characters in a string is its length. The position of a character within a string is called its index. Strings are zero indexed -- the first character is at index 0. The String.valueOf() methods are class methods that convert primitive types into String objects. The indexOf() method searches from left to right within a String for either a character or a substring.

ist.psu.edu School of Information Sciences and Technology Java Strings Methods for comparing strings: public boolean equals(Object anObject); // Overrides Object.equals() public boolean equalsIgnoreCase(String anotherString) public int compareTo(String anotherString) Two strings are equal if they have the same letters in the same order: String s1 = "hello"; String s2 = "Hello"; s1.equals(s2) // false s1.equals("hello”); // true Error: Using = = to compare two strings. For objects, o1 = = o2 means o1 and o2 are identical.

ist.psu.edu School of Information Sciences and Technology Java Strings Java Strings cannot be modified. Whenever you assign a new value to a String, Java must create a new String object and discard the old one. Objects of java.lang.StringBuffer class are strings that can be modified.

ist.psu.edu School of Information Sciences and Technology Java Strings A StringTokenizer breaks a string into tokens separated by delimiters, which by default value are the whitespace characters: StringTokenizer sTokenizer = new StringTokenizer("This is an English sentence."); This is an English sentence.

ist.psu.edu School of Information Sciences and Technology Control Structures –Sequence --- The statements in a program are executed in sequential order unless their flow is interrupted by one of the following control structures. –Invoke or Call a Method --- Invoking a method transfers control temporarily to a named method. Control returns to the point of invocation when the method is completed. –Decision/Selection--- The if, if/else, and switch statements are branching statements that allow choice by forking of the control path into two or more alternatives. –Repetition --- The for, while, and do-while statements are looping statements that allow the program to repeat a sequence of statements.

ist.psu.edu School of Information Sciences and Technology Control Structures No matter how large or small a program is, its flow of control can be built as a combination of these four structures. Note that each structure has one entry and one exit.

ist.psu.edu School of Information Sciences and Technology Repetition Repetition structure: a control structure that repeats a statement or a sequence of statements. A counting loop can be used if you know in advance how many iterations are needed. The for statement is used for counting loops. A while structure should be used if the loop body may be skipped entirely. The while statement is used. A do-while structure should be used only if a loop requires one or more iterations. The do-while- statement should be used.

ist.psu.edu School of Information Sciences and Technology Loop Elements The loop variable, which is used to specify the loop entry condition, must be initialized to an appropriate value and updated on each iteration. A loop's bound, which may be a count, a sentinel, or, more generally, a conditional bound, must be correctly specified in the loop-entry expression, and progress toward it must be made in the updater. An infinite loop may result if either the initializer, loop-entry expression, or updater expression is not correctly specified.

ist.psu.edu School of Information Sciences and Technology Homework Assignment This is an individual assignment. Read Raposa Chapter 4. Using Eclipse, write a Java class for each of the classes you designed for homework #2. Write another class (a program), the main class with the main() method, that creates an instance of each of these classes, then calls one method in each to output the method name. Due at the start of class Tuesday, 1/24. Hand in hard copies of the object definitions (classes) and of the source code.