Documents Found!
As seen in
Less Work, Better Grades
Join
Course Hero
Access
best resources
Ace
your classes
Ace your courses with Course Hero!
|
|
|
Study Smarter, Score Higher
Here are the top 5 related documents
...Chapter 9 - Object-Oriented Programming: Inheritance
Outline 9.1 9.2 9.3 9.4 9.5 9.6 9.7 Introduction Superclasses and Subclasses protected Members Relationship between Superclasses and Subclasses Case Study: ThreeLevel Inheritance Hi...
...1
Chapter 4 - Control Structures: Part 1
Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 if SingleSelection Statement 4.6 if else Selection Statement 4.7 while Repetition Statement 4.8 Formulating...
...Chapter 2 - Introduction to Java Applications
Outline
2.1 Introduction 2.2 A First Program in Java: Printing a Line of Text 2.3 Modifying Our First Java Program 2.4 Displaying Text in a Dialog Box 2.5 Another Java Application: Adding Integers 2.6 ...
...Chapter 3 - Introduction to Java Applets
Outline
3.1 Introduction 3.2 Sample Applets from the Java 2 Software Development Kit 3.3 Simple Java Applet: Drawing a String 3.4 Drawing Strings and Lines 3.5 Adding Floating-Point Numbers 3.6 ...
Document Content (unformatted)
Course Hero has millions of student submitted documents similar to the one
below including study guides, homework solutions, papers, exam answer keys and textbook solutions.
10 Chapter - Object-Oriented Programming: Polymorphism Outline 10.1 Introduction 10.2 Relationships Among Objects in an Inheritance Hierarchy 10.2.1 Invoking Superclass Methods from Subclass Objects 10.2.2 Using Superclass References with SubclassType Variables 10.2.3 Subclass Method Calls via SuperclassType Variables 10.3 Polymorphism Examples 10.4 Abstract Classes and Methods 10.5 Case Study: Inheriting Interface and Implementation 10.6 final Methods and Classes 10.7 Case Study: Payroll System Using Polymorphism 1 2003 Prentice Hall, Inc. All rights reserved. Chapter 10 - Object-Oriented Programming: Polymorphism Outline 10.8 10.9 10.10 10.11 Case Study: Creating and Using Interfaces Nested Classes TypeWrapper Classes for Primitive Types (Optional Case Study) Thinking About Objects: Incorporating Inheritance into the Elevator Simulation 10.12 (Optional) Discovering Design Patterns: Introducing Creational, Structural and Behavioral Design Patterns 10.12.1 Creational Design Patterns 10.12.2 Structural Design Patterns 10.12.3 Behavioral Design Patterns 10.12.4 Conclusion 10.12.5 Internet and WorldWideWeb Resources 2 2003 Prentice Hall, Inc. All rights reserved. 3 10.1 Introduction Polymorphism "Program in the general" Treat objects in same class hierarchy as if all superclass Abstract class Common functionality Makes programs extensible New classes added easily, can still be processed In our examples Use abstract superclass Shape Defines common interface (functionality) Point, Circle and Cylinder inherit from Shape Class Employee for a natural example 2003 Prentice Hall, Inc. All rights reserved. 10.2 Relationships Among Objects in an Inheritance Hierarchy Previously (Section 9.4), Circle inherited from Point Manipulated Point and Circle objects using references to invoke methods 4 This section Invoking superclass methods from subclass objects Using superclass references with subclass-type variables Subclass method calls via superclass-type variables Key concept subclass object can be treated as superclass object "is-a" relationship superclass is not a subclass object 2003 Prentice Hall, Inc. All rights reserved. 10.2.1 Invoking Superclass Methods from Subclass Objects Store references to superclass and subclass objects Assign a superclass reference to superclass-type variable Assign a subclass reference to a subclass-type variable Both straightforward 5 Assign a subclass reference to a superclass variable "is a" relationship 2003 Prentice Hall, Inc. All rights reserved. 1 // Fig. 1 1: HierarchyRelationshipT 0. est1 .java 2 // Assigning superclass and subclass references to superclass and 3 // subclasstype variables. HierarchyRelations 4 im por t javax.swing.JOptionPane; hipT est1 .java 5 6 public class HierarchyRelationshipT est1 { Line 11 7 Assign superclass 8 public static void main( String[] args ) reference to superclass9 { Assign superclass reference variable type 1 0 // assign superclass reference to superclasstype variable to superclass-type variable 11 Point3 point = new Point3( 30, 50 ); Line 14 12 Assign subclass reference to reference Assign subclass 13 // assign subclass reference to subclasstype variable subclass-type variable to subclass-type variable 1 4 Circle4 circle = new Circle4( 120, 89, 2.7 ); 15 1 6 // invoke toString on superclass object using superclass Invoke toString on Line 17 variable Invoke toString superclass object using on 1 7 String output = "Call Point3's toString with superclass" + superclass object superclass variable using 1 8 " reference to superclass object : \n" + point.toString(); superclass variable 1 9 Invoke toString on 20 // invoke toString on subclass object using subclass subclass object using Line 22 variable Invoke toString on subclass variable 21 output += "\n\nCall Circle4's toString with subclass" + subclass object using 22 " reference to subclass object : \n" + circle.toString(); subclass variable 23 Outline 6 2003 Prentice Hall, Inc. All rights reserved. 2 4 // invoke toString on subclass object using superclass Assign subclass reference to variable superclass-type variable Invoke toString on 25 Point3 pointRef = circle; 26 output += "\n\nCall Circle4's toString with superclass" + subclass object using HierarchyRelati 27 " reference to subclass object : \n" + pointRef.toString(); superclass variable .java onshipT est1 28 29 JOptionPane.showMessageDialog( null, output ); // display output Line 25 30 Assign subclass 3 1 System.exit( 0 ); reference to 32 superclass-type 33 } // end main 34 variable. 35 } // end class HierarchyRelationshipT est1 Outline 7 Line 27 Invoke toString on subclass object using superclass variable. 2003 Prentice Hall, Inc. All rights reserved. 10.2.2 Using Superclass References with SubclassType Variables Previous example Assigned subclass reference to superclass-type variable Circle "is a" Point 8 Assign superclass reference to subclass-type variable Compiler error No "is a" relationship Point is not a Circle Circle has data/methods that Point does not setRadius (declared in Circle) not declared in Point Cast superclass references to subclass references Called downcasting Invoke subclass functionality 2003 Prentice Hall, Inc. All rights reserved. 1 // Fig. 1 0.2: HierarchyRelationshipT est2.java 2 // Attem pt to assign a superclass reference to a subclasstype variable. 3 4 public class HierarchyRelationshipT est2 { 5 6 public static void main( String[] args ) 7 { 8 Point3 point = new Point3( 30, 50 ); 9 Circle4 circle; // subclasstype variable 1 0 11 // assign superclass reference to subclasstype variable 12 circle = point ; // Error : a Point3 is not a Circle4 Assigning superclass reference 13 } to subclass-type variable causes 1 4 15 } // end class HierarchyRelationshipT compiler error est2 Outline 9 HierarchyRelati onshipT est2.java Line 12 Assigning superclass reference to subclasstype variable causes compiler error. HierarchyRelationshipTest2.java:12: incompatible types found : Point3 required: Circle4 circle = point; // Error: a Point3 is not a Circle4 ^ 1 error 2003 Prentice Hall, Inc. All rights reserved. 10.2.3 Subclass Method Calls via SuperclassType variables Call a subclass method with superclass reference Compiler error Subclass methods are not superclass methods 10 2003 Prentice Hall, Inc. All rights reserved. 1 // Fig. 1 0.3: HierarchyRelationshipT est3.java 2 // Attem pting to invoke subclassonl y member methods through 3 // a superclass reference. 4 5 public class HierarchyRelationshipT est3 { 6 7 public static void main( String[] args ) 8 { 9 Point3 point ; 10 Circle4 circle = new Circle4( 120, 89, 2.7 ); 11 12 point = circle; // aim superclass reference at subclass object 13 14 // invoke superclass (Point3) methods on subclass 15 // (Circle4) object through superclass reference 16 int x = point.getX(); 17 int y = point.getY(); 18 point.setX( 1 0 ); 19 point.setY( 20 ); 20 point.toString(); 21 Outline 11 HierarchyRelati onshipT est3.java 2003 Prentice Hall, Inc. All rights reserved. 22 23 24 25 26 27 28 29 30 31 32 // attem pt to invoke subclassonl y (Circle4) methods on // subclass object through superclass (Point3) reference double radius = point.getRadius(); point.setRadius( 33.33 ); double diameter = point.getDiameter(); double circumference = point.getCircumference(); double area = point.getArea(); } // end main } // end class HierarchyRelationshipT est3 Outline 12 HierarchyRelati onshipT est3.java Lines 24-28 Attempt to invoke subclass-only (Circle4) methods on subclass object through superclass (Point3) reference. Attempt to invoke subclassonly (Circle4) methods on subclass object through superclass (Point3) reference. 2003 Prentice Hall, Inc. All rights reserved. HierarchyRelationshipT est3.java:2 4: cannot resol ve symbol symbol : method getRadius () location: class Point3 double radius = point.getRadius(); ^ HierarchyRelationshipT est3.java:25: cannot resol ve symbol symbol : method setRadius (double) location: class Point3 point.setRadius( 33.33 ); ^ HierarchyRelationshipT est3.java:26: cannot resol ve symbol symbol : method getDiameter () location: class Point3 double diameter = point.getDiameter(); ^ HierarchyRelationshipT est3.java:27 cannot resol : ve symbol symbol : method getCircumference () location: class Point3 double circumference = point.getCircumference(); ^ HierarchyRelationshipT est3.java:28: cannot resol ve symbol symbol : method getArea () location: class Point3 double area = point.getArea(); ^ 5 errors Outline 13 HierarchyRelati onshipT est3.java 2003 Prentice Hall, Inc. All rights reserved. 14 10.3 Polymorphism Examples Examples Suppose Rectangle derives from Quadrilateral Rectangle more specific than Quadrilateral Any operation on Quadrilateral can be done on Rectangle (i.e., perimeter, area) Suppose designing video game Superclass SpaceObject Subclasses Martian, SpaceShip, LaserBeam Contains method draw To refresh screen Send draw message to each object Same message has "many forms" of results 2003 Prentice Hall, Inc. All rights reserved. 15 10.3 Polymorphism Examples Video game example, continued Easy to add class Mercurian Extends SpaceObject Provides its own implementation of draw Programmer does not need to change code Calls draw regardless of object's type Mercurian objects "plug right in" 2003 Prentice Hall, Inc. All rights reserved. 16 10.4 Abstract Classes and Methods Abstract classes Are superclasses (called abstract superclasses) Cannot be instantiated Incomplete subclasses fill in "missing pieces" Concrete classes Can be instantiated Implement every method they declare Provide specifics 2003 Prentice Hall, Inc. All rights reserved. 17 10.4 Abstract Classes and Methods (Cont.) Abstract classes not required, but reduce client code dependencies To make a class abstract Declare with keyword abstract Contain one or more abstract methods public abstract void draw(); Abstract methods No implementation, must be overridden 2003 Prentice Hall, Inc. All rights reserved. 18 10.4 Abstract Classes and Methods (Cont.) Application example Abstract class Shape Declares draw as abstract method Circle, Triangle, Rectangle extends Shape Each must implement draw Each object can draw itself Iterators Array, ArrayList (Chapter 22) Walk through list elements Used in polymorphic programming to traverse a collection 2003 Prentice Hall, Inc. All rights reserved. 10.5 Case Study: Inheriting Interface and Implementation Make abstract superclass Shape Abstract method (must be implemented) getName, print Default implementation does not make sense 19 Methods may be overridden getArea, getVolume Default implementations return 0.0 If not overridden, uses superclass default implementation Subclasses Point, Circle, Cylinder 2003 Prentice Hall, Inc. All rights reserved. 10.5 Case Study: Inheriting Interface and Implementation Shape 20 Point Circle Cylinder Fig. 10.4 Shape hierarchy class diagram. 2003 Prentice Hall, Inc. All rights reserved. 10.6 Case Study: Inheriting Interface and Implementation getArea 0.0 getVolume 0.0 getName = 0 print = 0 Shape 21 Point 0.0 0.0 "Point" [x,y] Circle pr2 0.0 "Circle" center=[x,y]; radius=r center=[x,y]; radius=r; height=h Cylinder 2pr2 +2prh pr2h "Cylinder" Fig. 10.5 Polimorphic interface for the Shape hierarchy classes. 2003 Prentice Hall, Inc. All rights reserved. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 // Fig. 1 0.6: Shape.java // Shape abstractsuperclass declaration. public abstract class Shape extends Object { // retur n area of shape; 0.0 by default public double getArea() Keyword abstract { declares class Shape as retur n 0.0; abstract class } // retur n volume of shape; 0.0 by default public double getVolume() { retur n 0.0; } // abstract method, overridden by subclasses public abstract String getName(); } // end abstract class Shape Outline Shape.java 22 Line 4 Keyword abstract declares class Shape as abstract class Line 19 Keyword abstract declares method getName as abstract method Keyword abstract declares method getName as abstract method 2003 Prentice Hall, Inc. All rights reserved. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 // Fig. 1 : Point.java 0.7 // Point class declaration inherits from Shape. public class Point extends Shape { private int x; // x par t of coordinate pair private int y ; // y par t of coordinate pair // noargument constr uctor; x and y default to 0 public Point() { // im plicit call to Object constr uctor occurs here } // constr uctor public Point( int xValue, int yValue ) { // im plicit call to Object constr uctor occurs here x = xValue; // no need for validation y = yValue; // no need for validation } // set x in coordinate pair public void setX( int xValue ) { x = xValue; // no need for validation } Outline Point.java 23 2003 Prentice Hall, Inc. All rights reserved. 28 // retur n x from coordinate pair 29 public int getX() 30 { 3 1 retur n x; 32 } 33 34 // set y in coordinate pair 35 public void setY( int yValue ) 36 { 37 y = yValue; // no need for validation 38 } 39 40 // retur n y from coordinate pair Override 41 public int getY() abstract 42 { method getName. 43 retur n y; 44 } 45 46 // override abstract method getName to retur n "Point" 4 7 public String getName() 48 { 49 retur n "Point"; 50 } 5 1 52 // override toString to retur n String representation of Point 53 public String toString() 54 { 55 retur n "[" + getX() + ", " + getY() + "]"; 56 } 57 58 } // end class Point Outline Point.java 24 Lines 47-50 Override abstract method getName. 2003 Prentice Hall, Inc. All rights reserved. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 // Fig. 1 0.8: Circle.java // Circle class inherits from Point. public class Circle extends Point { private double radius; // Circle's radius // noargument constr uctor; radius defaults to 0.0 public Circle() { // im plicit call to Point constr uctor occurs here } // constr uctor public Circle( int x, int y , double radiusValue ) { super( x, y ); // call Point constr uctor setR adius( radiusValue ); } // set radius public void setRadius( double radiusValue ) { radius = ( radiusValue < 0.0 ? 0.0 : radiusValue ); } Outline Circle.java 25 2003 Prentice Hall, Inc. All rights reserved. 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 // retur n radius public double getRadius() { retur n radius; } // calculate and return diameter public double getDiameter() { retur n 2 * getRadius(); } // calculate and return circumference Override method public double getCircumference() getArea to return { circle area retur n Math.PI * getDiameter(); } // override method getArea to retur n Circle area public double getArea() { retur n Math.PI * getRadius() * getRadius(); } Outline Circle.java Lines 45-48 Override method getArea to return circle area. 26 2003 Prentice Hall, Inc. All rights reserved. 50 // override abstract method getName to retur n "Circle" 5 1 public String getName() Override 52 { 53 retur n "Circle"; abstract 54 } method getName 55 56 // override toString to retur n String representation of Circle 57 public String toString() 58 { 59 retur n "Center = " + super.toString() + "; R adius = " + getR adius(); 60 } 61 62 } // end class Circle Outline Circle.java 27 Lines 51-54 Override abstract method getName. 2003 Prentice Hall, Inc. All rights reserved. 1 // Fig. 1 0.9: Cy linder .java 2 // Cy linder class inherits from Circle. 3 4 public class Cy linder extends Circle { 5 private double height ; // Cy linder's height 6 7 // noargument constr uctor; height defaults to 0.0 8 public Cy linder() 9 { 10 // im plicit call to Circle constr uctor occurs here 11 } 12 13 // constr uctor 14 public Cy linder( int x, int y , double radius, double heightValue ) 15 { 16 super( x, y , radius ); // call Circle constr uctor 17 setHeight( heightValue ); 18 } 19 20 // set Cy linder's height 21 public void setHeight( double heightValue ) 22 { 23 height = ( heightValue < 0.0 ? 0.0 : heightValue ); 24 } 25 Outline Cy linder .java 28 2003 Prentice Hall, Inc. All rights reserved. 26 // get Cy linder's height Override method 27 public double getHeight() getArea to return 28 { cylinder area 29 retur n height ; 30 } 31 32 // override abstract method getArea to return Cy linder area Override method getVolume to 33 public double getArea() return cylinder volume 34 { 35 retur n 2 * super.getArea() + getCircumference() * getHeight(); 36 } 37 38 // override abstract method getVolume to retur n Cy linder volume 39 public double getVolume() Override 40 { abstract 41 retur n super.getArea() * getHeight(); method getName 42 } 43 44 // override abstract method getName to return "Cy linder" 45 public String getName() 46 { Outline Cy linder .java Lines 33-36 Override method getArea to return cylinder area 29 Lines 39-42 Override method getV olume to return cylinder volume Lines 45-48 Override abstract method getName 2003 Prentice Hall, Inc. All rights reserved. 49 50 // override toString to return String representation of Cy linder 51 public String toString() 52 { 53 retur n super.toString() + "; Height = " + getHeight(); 54 } 55 56 } // end class Cy linder Outline Cy linder .java 30 2003 Prentice Hall, Inc. All rights reserved. 1 // Fig. 1 1 0.0: A bstractInheritanceT est.java 2 // Driver for shape, point, circle, cy linder hierarchy . 3 im por t java.text.DecimalFor mat ; 4 im por t javax.swing.JOptionPane; 5 6 public class A bstractInheritanceT est { 7 8 public static void main( String args[] ) 9 { 10 // set floatingpoint number for mat 11 DecimalFor mat twoDigits = new DecimalFor mat( "0.00" ); 12 13 // create Point, Circle and Cy linder objects 14 Point point = new Point( 7, 11 ); 15 Circle circle = new Circle( 22, 8, 3.5 ); 16 Cy linder cy linder = new Cy linder( 20, 30, 3.3, 1 5 ); 0.7 17 18 // obtain name and string representation of each object 19 String output = point.getName() + ": " + point + "\n" + 20 circle.getName() + ": " + circle + "\n" + 21 cy linder .getName() + ": " + cy linder + "\n"; 22 23 Shape arrayOfShapes[] = new Shape[ 3 ]; // create Shape array 24 Outline 31 A bstractInherit anceT est.java 2003 Prentice Hall, Inc. All rights reserved. 25 // aim arrayOfShapes[ 0 ] at subclass Point object 26 arrayOfShapes[ 0 ] = point ; 27 28 // aim arrayOfShapes[ 1 ] at subclass Circle object Create an array of A bstractInherit 29 arrayOfShapes[ 1 ] = circle; through Loop objects generic Shape anceT est.java 30 arrayOfShapes to get 3 1 // aim arrayOfShapes[ 2 ] at subclass Cy linder object name, string representation, Lines 26-32 32 arrayOfShapes[ 2 ] = cy linder; area and volume of every an array of 33 Create shape in array 34 // loop through arrayOfShapes to get name, string generic Shape 35 // representation, area and volume of ever y Shape in array objects 36 for ( int i = 0; i < arrayOfShapes.length; i++ ) { 37 output += "\n\n" + arrayOfShapes[ i ].getName() + ": " + Lines 36-42 38 arrayOfShapes[ i ].toString() + "\nArea = " + 39 twoDigits.for mat( arrayOfShapes[ i ].getArea() ) + Loop through 40 "\nVolume = " + arrayOfShapes to 41 twoDigits.for mat( arrayOfShapes[ i ].getVolume() ); get name, string 42 } representation, area 43 and volume of every 44 JOptionPane.showMessageDialog( null, output ); // display output shape in array 45 46 System.exit( 0 ); 4 7 48 } // end main 49 50 } // end class A bstractInheritanceT est Outline 32 2003 Prentice Hall, Inc. All rights reserved. 33 2003 Prentice Hall, Inc. All rights reserved. 34 10.6 final Methods and Classes final methods Cannot be overridden private methods are implicitly final static methods are implicitly final final classes Cannot be superclasses Methods in final classes are implicitly final e.g., class String 2003 Prentice Hall, Inc. All rights reserved. 10.7 Case Study: Payroll System Using Polymorphism Create a payroll program Use abstract methods and polymorphism 35 Problem statement 4 types of employees, paid weekly Salaried (fixed salary, no matter the hours) Hourly (overtime [>40 hours] pays time and a half) Commission (paid percentage of sales) Base-plus-commission (base salary + percentage of sales) Boss wants to raise pay by 10% 2003 Prentice Hall, Inc. All rights reserved. 10.9 Case Study: Payroll System Using Polymorphism Superclass Employee Abstract method earnings (returns pay) abstract because need to know employee type Cannot calculate for generic employee 36 Other classes extend Employee Employee SalariedEmployee CommissionEmployee HourlyEmployee BasePlusCommissionEmployee 2003 Prentice Hall, Inc. All rights reserved. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 // Fig. 1 12: Em ployee.java 0. // Em ployee abstract superclass. public abstract class Em ployee { private String firstName; private String lastName; private String socialSecurityNumber; Outline Declares class Employee as abstract class. Employee.java Line 4 Declares class Employee as abstract class. 37 // constr uctor public Em ployee( String first, String last, String ssn ) { firstName = first ; lastName = last ; socialSecurityNumber = ssn; } // set first name public void setFirstName( String first ) { firstName = first ; } 2003 Prentice Hall, Inc. All rights reserved. 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 // retur n first name public String getFirstName() { retur n firstName; } // set last name public void setLastName( String last ) { lastName = last ; } // retur n last name public String getLastName() { retur n lastName; } // set social security number public void setSocialSecurityNumber( String number ) { socialSecurityNumber = number; // should validate } Outline Employee.java 38 2003 Prentice Hall, Inc. All rights reserved. 47 // retur n social security number 48 public String getSocialSecurityNumber() 49 { 50 retur n socialSecurityNumber; 51 } 52 53 // retur n String representation of Em ployee object 54 public String toString() 55 { 56 retur n getFirstName() + " " + getLastName() + 57 "\nsocial security number : " + getSocialSecurityNumber(); 58 } 59 Abstract method 60 // abstract method overridden by subclasses 61 public abstract double earnings(); overridden by subclasses 62 63 } // end abstract class Em ployee Outline Employee.java Line 61 Abstract method overridden by subclasses. 39 2003 Prentice Hall, Inc. All rights reserved. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 // Fig. 1 13: SalariedEm ployee.java 0. // SalariedEm ployee class extends Em ployee. public class SalariedEm ployee extends Em ployee { private double weekl ySalar y; // constr uctor Use superclass constructor public SalariedEm ployee( String first, String last, basic fields. String socialSecurityNumber , double salar y ) { super( first, last, socialSecurityNumber ); setWeekl ySalar y( salar y ); } // set salaried em ployee's salar y public void setWeekl ySalar y( double salar y ) { weekl ySalar y = salar y < 0.0 ? 0.0 : salar y; } // retur n salaried em ployee's salar y public double getWeekl ySalar y() { retur n weekl ySalar y ; } Outline 40 SalariedEmploye e.java for Line 11 Use superclass constructor for basic fields. 2003 Prentice Hall, Inc. All rights reserved. 27 28 29 30 31 32 33 34 35 36 37 38 39 40 // calculate salaried em ployee's pay; // override abstract method earnings in Em ployee public double earnings() { retur n getWeekl ySalar y(); } Must implement abstract // retur n String representation of SalariedEm ployee object public String toString() { retur n "\nsalaried em ployee: " + super.toString(); } } // end class SalariedEm ployee Outline 41 SalariedEmploye e.java Lines 29-32 Must implement abstract method earnings. method earnings. 2003 Prentice Hall, Inc. All rights reserved. 1 // Fig. 1 1 0.4: Hourl yEm ployee.java 2 // Hourl yEm ployee class extends Em ployee. 3 4 public class Hourl yEm ployee extends Em ployee { 5 private double wage; // wage per hour 6 private double hours; // hours worked for week 7 8 // constr uctor 9 public Hourl yEm ployee( String first, String last, 1 0 String socialSecurityNumber , double hourl yWage, double hoursWorked ) 11 { 12 super( first, last, socialSecurityNumber ); 13 setWage( hourl yWage ); 1 4 setHours( hoursWorked ); 15 } 1 6 1 7 // set hourl y em ployee's wage 1 8 public void setWage( double wageAmount ) 1 9 { 20 wage = wageAmount < 0.0 ? 0.0 : wageAmount ; 21 } 22 23 // retur n wage 2 4 public double getWage() 25 { 26 retur n wage; 27 } 28 Outline 42 Hourl yEmployee.j ava 2003 Prentice Hall, Inc. All rights reserved. 29 // set hourl y em ployee's hours worked 30 public void setHours( double hoursWorked ) 3 1 { 32 hours = ( hoursWorked >= 0.0 && hoursWorked <= 1 68.0 ) ? 33 hoursWorked : 0.0; 34 } 35 36 // retur n hours worked 37 public double getHours() 38 { 39 retur n hours; 40 } 41 42 // calculate hourl y em ployee's pay; 43 // override abstract method ear nings in Em ployee 44 public double ear nings() Must implement abstract 45 { method earnings. 46 if ( hours <= 40 ) // no over time 4 7 retur n wage * hours; 48 else 49 retur n 40 * wage + ( hours 40 ) * wage * 1 .5; 50 } 5 1 52 // retur n String representation of Hourl yEm ployee object 53 public String toString() 54 { 55 retur n "\nhourl y em ployee: " + super.toString(); 56 } 57 58 } // end class Hourl yEm ployee Outline 43 Hourl yEmployee.j ava Lines 44-50 Must implement abstract method earnings. 2003 Prentice Hall, Inc. All rights reserved. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 // Fig. 1 15: CommissionEm ployee.java 0. // CommissionEm ployee class extends Em ployee. public class CommissionEm ployee extends Em ployee { private double grossSales; // gross weekl y sales private double commissionRate; // commission percentage // constr uctor public CommissionEm ployee( String first, String last, String socialSecurityNumber , double grossWeekl ySales, double percent ) { super( first, last, socialSecurityNumber ); setGrossSales( grossWeekl ySales ); setCommissionRate( percent ); } // set commission em ployee's rate public void setCommissionRate( double rate ) { commissionRate = ( rate > 0.0 && rate < 1 .0 ) ? rate : 0.0; } // retur n commission em ployee's rate public double getCommissionRate() { retur n commissionRate; } Outline 44 CommissionEmplo yee.java 2003 Prentice Hall, Inc. All rights reserved. 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 // set commission em ployee's weekl y base salar y public void setGrossSales( double sales ) { grossSales = sales < 0.0 ? 0.0 : sales; } // retur n commission em ployee's gross sales amount public double getGrossSales() { retur n grossSales; } // calculate commission em ployee's pay; Must implement abstract // override abstract method earnings in Em ployee method earnings. public double earnings() { retur n getCommissionRate() * getGrossSales(); } // retur n String representation of CommissionEm ployee object public String toString() { retur n "\ncommission em ployee: " + super.toString(); } } // end class CommissionEm ployee Outline 45 CommissionEmplo yee.java Lines 44-47 Must implement abstract method earnings. 2003 Prentice Hall, Inc. All rights reserved. 1 // Fig. 1 1 0.6: BasePlusCommissionEm ployee.java 2 // BasePlusCommissionEm ployee class extends CommissionEm ployee. 3 4 public class BasePlusCommissionEm ployee extends CommissionEm ployee { 5 private double baseSalar y; // base salar y per week 6 7 // constr uctor 8 public BasePlusCommissionEm ployee( String first, String last, 9 String socialSecurityNumber , double grossSalesAmount, 1 0 double rate, double baseSalar yAmount ) 11 { 12 super( first, last, socialSecurityNumber , grossSalesAmount, rate ); 13 setBaseSalar y( baseSalar yAmount ); 1 4 } 15 1 6 // set basesalaried commission em ployee's base salar y 1 7 public void setBaseSalar y( double salar y ) 1 8 { 1 9 baseSalar y = salar y < 0.0 ? 0.0 : salar y; 20 } 21 22 // retur n basesalaried commission em ployee's base salar y 23 public double getBaseSalar y() 2 4 { 25 retur n baseSalar y; 26 } 27 Outline 46 BasePlusCommiss ionEmployee.jav a 2003 Prentice Hall, Inc. All rights reserved. 28 // calculate basesalaried commission em ployee's ear nings; 29 // override method ear nings in CommissionEm ployee 30 public double ear nings() Override method earnings 3 1 { in CommissionEmployee 32 retur n getBaseSalar y() + super.ear nings(); 33 } 34 35 // retur n String representation of BasePlusCommissionEm ployee 36 public String toString() 37 { 38 retur n "\nbasesalaried commission em ployee: " + 39 super.getFirstName() + " " + super.getLastName() + 40 "\nsocial security number : " + super.getSocialSecurityNumber(); 41 } 42 43 } // end class BasePlusCommissionEm ployee Outline 47 BasePlusCommiss ionEmployee.jav a Lines 30-33 Override method earnings in CommissionEmplo yee 2003 Prentice Hall, Inc. All rights reserved. 1 // Fig. 1 1 PayrollSystemT 0.: 7 est.java 2 // Em ployee hierarchy test program. 3 im por t java.text.DecimalFor mat ; 4 im por t javax.swing.JOptionPane; 5 6 public class PayrollSystemT est { 7 8 public static void main( String[] args ) 9 { 10 DecimalFor mat twoDigits = new DecimalFor mat( "0.00" ); 11 12 // create Em ployee array 13 Em ployee em ployees[] = new Em ployee[ 4 ]; 14 15 // initialize array with Em ployees 16 em ployees[ 0 ] = new SalariedEm ployee( "John", "Smith", 17 "111111111", 800.00 ); 18 em ployees[ 1 ] = new CommissionEm ployee( "Sue", "Jones", 19 "222222222", 1 0000, .06 ); 20 em ployees[ 2 ] = new BasePlusCommissionEm ployee( "Bob", "Lewis", 21 "333333333", 5000, .04, 300 ); 22 em ployees[ 3 ] = new Hourl yEm ployee( "Karen", "Price", 23 "444444444", 1 5, 40 ); 6.7 24 25 String output = ""; 26 Outline 48 P ayrollSystemT est .java 2003 Prentice Hall, Inc. All rights reserved. 27 // genericall y process each element in array em ployees 28 for ( int i = 0; i < em ployees.length; i++ ) { 29 output += em ployees[ i ].toString(); 30 P ayrollSystemT est 31 // deter mine whether element is a .java BasePlusCommissionEm ployee Determine whether element is a 32 if ( em ployees[ i ] instanceof Line BasePlusCommissionEmpl 32 BasePlusCommissionEm ployee ) { Determine whether oyee 33 element is a 34 // downcast Em ployee reference to BasePlusCommiss 35 // BasePlusCommissionEm ployee reference Downcast Employee reference to ionEmployee 36 BasePlusCommissionEm ployee currentEm ployee = 37 ( BasePlusCommissionEmBasePlusCommissionEmployee ployee ) em ployees[ i ]; 38 reference Line 37 39 double oldBaseSalar y = Downcast Employee currentEm ployee.getBaseSalar y(); 40 output += "\nold base salar y : $" + oldBaseSalar y; reference to BasePlusCommiss 41 ionEmployee 42 currentEm ployee.setBaseSalar y( 11 .0 * reference oldBaseSalar y ); 43 output += "\nnew base salar y with 1 0% increase is: $" + 44 currentEm ployee.getBaseSalar y(); 45 46 } // end if 47 48 output += "\nearned $" + em ployees[ i ].earnings() + "\n"; 2003 Prentice Hall, Inc. 49 All rights reserved. 50 } // end for Outline 49 52 // get type name of each object in em ployees array 53 for ( int j = 0; j < em ployees.length; j++ ) 54 output += "\nEm ployee " + j + " is a " + 55 em ployees[ j ].getClass().getName(); name of each P Get type ayrollSystemT est 56 object in employees.java 57 JOptionPane.showMessageDialog( null, output ); // display array output 58 System.exit( 0 ); Lines 53-55 59 Get type name of each 60 } // end main object in employees 61 array 62 } // end class PayrollSystemT est Outline 50 2003 Prentice Hall, Inc. All rights reserved. 10.8 Case Study: Creating and Using Interfaces Use interface Shape Replace abstract class Shape 51 Interface Declaration begins with interface keyword Classes implement an interface (and its methods) Contains public abstract methods Classes (that implement the interface) must implement these methods 2003 Hall, Prentice Inc. All rights reserved. 1 2 3 4 5 6 7 8 9 // Fig. 1 1 0.8: Shape.java Classes // Shape interface declaration. that implement Shape must implement these methods Outline Shape.java 52 public interface Shape { public double getArea(); // calculate area public double getVolume(); // calculate volume public String getName(); // return shape name } // end interface Shape Lines 5-7 Classes that implement Shape must implement these methods 2003 Prentice Hall, Inc. All rights reserved. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 // Fig. 1 1 0.9: Point.java // Point class declaration im plements interface Shape. public class Point extends Object im plements Shape { private int x; // x par t of coordinate pair private int y ; // y par t of coordinate pair // noargument constr uctor; x and y default to 0 Point implements interface public Point() { // im plicit call to Object constr uctor occurs here } // constr uctor public Point( int xValue, int yValue ) { // im plicit call to Object constr uctor occurs here x = xValue; // no need for validation y = yValue; // no need for validation } // set x in coordinate pair public void setX( int xValue ) { x = xValue; // no need for validation } Outline Point.java Line 4 Point implements Shape interface Shape 53 2003 Prentice Hall, Inc. All rights reserved. 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 // retur n x from coordinate pair public int getX() { retur n x; } // set y in coordinate pair public void setY( int yValue ) { y = yValue; // no need for validation } // retur n y from coordinate pair public int getY() { retur n y ; } Outline Point.java 54 2003 Prentice Hall, Inc. All rights reserved. 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 // declare abstract method getArea public double getArea() { retur n 0.0; } // declare abstract method getVolume public double getVolume() { retur n 0.0; } Outline Point.java 55 Lines 47-59 Implement methods specified Implement methods by interface Shape specified by interface Shape // override abstract method getName to return "Point" public String getName() { retur n "Point"; } // override toString to return String representation of Point public String toString() { retur n "[" + getX() + ", " + getY() + "]"; } } // end class Point 2003 Prentice Hall, Inc. All rights reserved. 1 // Fig. 1 0.20: InterfaceT est.java 2 // T est Point, Circle, Cy linder hierarchy with interface Shape. 3 im por t java.text.DecimalFor mat ; 4 im por t javax.swing.JOptionPane; 5 6 public class InterfaceT est { 7 8 public static void main( String args[] ) 9 { 10 // set floatingpoint number for mat 11 DecimalFor mat twoDigits = new DecimalFor mat( "0.00" ); 12 13 // create Point, Circle and Cy linder objects 14 Point point = new Point( 7, 11 ); 15 Circle circle = new Circle( 22, 8, 3.5 ); 16 Cy linder cy linder = new Cy linder( 20, 30, 3.3, 1 5 ); 0.7 17 18 // obtain name and string representation of each object 19 String output = point.getName() + ": " + point + "\n" + Create Shape array 20 circle.getName() + ": " + circle + "\n" + 21 cy linder .getName() + ": " + cy linder + "\n"; 22 23 Shape arrayOfShapes[] = new Shape[ 3 ]; // create Shape array 24 Outline 56 InterfaceT est.ja va Line 23 Create Shape array 2003 Prentice Hall, Inc. All rights reserved. 25 // aim arrayOfShapes[ 0 ] at subclass Point object 26 arrayOfShapes[ 0 ] = point ; 27 28 // aim arrayOfShapes[ 1 ] at subclass Circle object InterfaceT est.ja 29 arrayOfShapes[ 1 ] = circle; va 30 Loop through arrayOfShapes to 3 1 // aim arrayOfShapes[ 2 ] at subclass Cy string representation, area linder object get name, Lines 36-42 32 arrayOfShapes[ 2 ] = cy linder; and volume of every shape in array 33 Loop through 34 // loop through arrayOfShapes to get name, string arrayOfShapes to 35 // representation, area and volume of ever y Shape in array get name, string 36 for ( int i = 0; i < arrayOfShapes.length; i++ ) { representation, area 37 output += "\n\n" + arrayOfShapes[ i ].getName() + ": " + and volume of every 38 arrayOfShapes[ i ].toString() + "\nArea = " + 39 twoDigits.for mat( arrayOfShapes[ i ].getArea() ) + shape in array. 40 "\nVolume = " + 41 twoDigits.for mat( arrayOfShapes[ i ].getVolume() ); 42 } 43 44 JOptionPane.showMessageDialog( null, output ); // display output 45 46 System.exit( 0 ); 4 7 48 } // end main 49 50 } // end class InterfaceT est Outline 57 2003 Prentice Hall, Inc. All rights reserved. Outline 58 InterfaceT est.ja va 2003 Prentice Hall, Inc. All rights reserved. 10.8 Case Study: Creating and Using Interfaces (Cont.) Implementing Multiple Interface Provide common-separated list of interface names after keyword implements 59 Declaring Constants with Interfaces public interface Constants { public static final int ONE = 1; public static final int TWO = 2; public static final int THREE = 3; } 2003 Prentice Hall, Inc. All rights reserved. 60 10.9 Nested Classes Top-level classes Not declared inside a class or a method Nested classes Declared inside other classes Inner classes Non-static nested classes 2003 Prentice Hall, Inc. All rights reserved. 1 // Fig. 1 0.21: Time.java 2 // Time class declaration with set and get methods. 3 im por t java.text.DecimalFor mat ; 4 5 public class Time { 6 private int hour; // 0 23 7 private int minute; // 0 59 8 private int second; // 0 59 9 10 // one for matting object to share in toString and toUniversalString 11 private static DecimalFor mat twoDigits = new DecimalFor mat( "00" ); 12 13 // Time constr uctor initializes each instance variable to zero; 14 // ensures that Time object star ts in a consistent state 15 public Time() 16 { 17 this( 0, 0, 0 ); // invoke Time constr uctor with three arguments 18 } 19 20 // Time constr uctor : hour supplied, minute and second defaulted to 0 21 public Time( int h ) 22 { 23 this( h, 0, 0 ); // invoke Time constr uctor with three arguments 24 } 25 Outline T ime.java 61 2003 Prentice Hall, Inc. All rights reserved. 26 // Time constr uctor : hour and minute supplied, second defaulted to 0 27 public Time( int h, int m ) 28 { 29 this( h, m, 0 ); // invoke Time constr uctor with three arguments 30 } 3 1 32 // Time constr uctor : hour , minute and second supplied 33 public Time( int h, int m, int s ) 34 { 35 setTime( h, m, s ); 36 } 37 38 // Time constr uctor : another Time3 object supplied 39 public Time( Time time ) 40 { 41 // invoke Time constr uctor with three arguments 42 this( time.getHour(), time.getMinute(), time.getSecond() ); 43 } 44 45 // Set Methods 46 // set a new time value using universal time; perfor m 4 7 // validity checks on data; set invalid values to zero 48 public void setTime( int h, int m, int s ) 49 { 50 setHour( h ); // set the hour 5 1 setMinute( m ); // set the minute 52 setSecond( s ); // set the second 53 } 54 Outline T ime.java 62 2003 Prentice Hall, Inc. All rights reserved. 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 // validate and set hour public void setHour( int h ) { hour = ( ( h >= 0 && h < 2 4 ) ? h : 0 ); } // validate and set minute public void setMinute( int m ) { minute = ( ( m >= 0 && m < 60 ) ? m : 0 ); } // validate and set second public void setSecond( int s ) { second = ( ( s >= 0 && s < 60 ) ? s : 0 ); } // Get Methods // get hour value public int getHour() { retur n hour; } Outline T ime.java 63 2003 Prentice Hall, Inc. All rights reserved. 80 // get minute value 8 1 public int getMinute() 82 { 83 retur n minute; 84 } 85 86 // get second value 87 public int getSecond() 88 { 89 retur n second; 90 } 9 1 92 // conver t to String in universaltime for mat Override method 93 public String toUniversalString() java.lang.Object.toString 94 { 95 retur n twoDigits.for mat( getHour() ) + ":" + 96 twoDigits.for mat( getMinute() ) + ":" + 97 twoDigits.for mat( getSecond() ); 98 } 99 1 00 // conver t to String in standardtime for mat 1 1 public String toString() 0 1 02 { 1 03 retur n ( ( getHour() == 12 || getHour() == 0 ) ? 1 04 12 : getHour() % 12 ) + ":" + twoDigits.for mat( getMinute() ) + 1 05 ":" + twoDigits.for mat( getSecond() ) + 1 06 ( getHour() < 12 ? " AM" : " PM" ); 1 07 } 1 08 1 09 } // end class Time Outline T ime.java 64 Lines 101-107 Override method java.lang.Objec t.toString 2003 Prentice Hall, Inc. All rights reserved. 1 // Fig. 1 0.22: TimeT estWindow .java 65 JFrame provides basic window 2 // Inner class declarations used to create event handlers. attributes and behaviors 3 im por t java.awt.*; 4 im por t java.awt.event.*; 5 im por t javax.swing.*; T imeT estWindow .ja 6 va 7 public class TimeT estWindow extends JFrame { 8 private Time time; 9 private JLabel hourLabel, minuteLabel, secondLabel; Line 7 1 0 private JT extField hourField, minuteField, secondField, JFrame provides displayField; basic window 11 private JButton exitButton; attributes and 12 JFrame (unlike JApplet) 13 // set up GUI behaviors has constructor 1 4 public TimeT estWindow() 15 { Instantiate Time object Line 17 1 6 // call JFrame constr uctor to set title bar string JFrame (unlike 1 7 super( "Inner Class Demonstration" ); JApplet) has 1 8 1 9 time = new Time(); // create Time object constructor 20 21 // use inherited method getContentPane to get window's content Line 19 pane Instantiate T ime 22 Container container = getContentPane(); 23 container .setLayout( new FlowLayout() ); // change layout object 2 4 25 // set up hourLabel and hourField 26 hourLabel = new JLabel( "Set Hour" ); 27 hourField = new JT extField( 1 0 ); 28 container .add( hourLabel ); 29 container .add( hourField ); 30 Outline 2003 Prentice Hall, Inc. All rights reserved. 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 // set up minuteLabel and minuteField minuteLabel = new JLabel( "Set Minute" ); minuteField = new JT extField( 1 0 ); container .add( minuteLabel ); container .add( minuteField ); // set up secondLabel and secondField secondLabel = new JLabel( "Set Second" ); secondField = new JT extField( 1 0 ); container .add( secondLabel ); container .add( secondField ); // set up displayField displayField = new JT extField( 30 ); displayField.setEditable( false ); container .add( displayField ); // set up exitButton exitButton = new JButton( "Exit" ); container .add( exitButton ); Outline 66 T imeT estWindow .ja va Line 53 Instantiate object of inner-class that implements ActionListener. Instantiate object of innerclass that implements ActionListener // create an instance of inner class ActionEventHandler ActionEventHandler handler = new ActionEventHandler(); 2003 Prentice Hall, Inc. All rights reserved. 55 // register event handlers; the object referenced by 67 handler 56 // is the ActionListener , which contains method actionPerfor med 57 // that will be called to handle action events generated T imeT estWindow .ja by Register va 58 // hourField, minuteField, secondField and exitButton ActionEventHandler with GUI Lines 59-62 59 hourField.addActionListener( handler ); components Register 60 minuteField.addActionListener( handler ); ActionEventHand 61 secondField.addActionListener( handler ); ler with GUI components. 62 exitButton.addActionListener( handler ); 63 64 } // end constr uctor 65 66 // display time in displayField 67 public void displayTime() 68 { 69 displayField.setT ext( "The time is: " + time ); 70 } 71 72 // launch application: create, size and display TimeT estWindow; 73 // when main ter minates, program continues execution because a 74 // window is displayed by the statements in main 75 public static void main( String args[] ) 2003 Prentice Hall, Inc. All rights reserved. Outline 84 // inner class declaration for handling JT extField and JButton events 85 private class ActionEventHandler im plements ActionListener { T imeT estWindow .ja 86 87 // method to handle action events Declare inner class that implements va 88 public void actionPerfor med( ActionEvent event ) ActionListener interface When user presses JButton or Enter key, 89 { Line 85 method actionPerformed is invoked 90 // user pressed exitButton Declare inner class 9 1 if ( event.getSource() == exitButton ) 92 System.exit( 0 ); // ter minate the application Must implement method actionPerformed 93 of ActionListener Line 88 94 // user pressed Enter key in hourField Must implement 95 else if ( event.getSource() == hourField ) { method Determine action depending 96 time.setHour( Integer .parseInt( actionPerf or on where event originated med 97 event.getActionCommand() ) ); 98 hourField.setT ext( "" ); Line 88 99 } 1 00 When user presses 1 1 // user pressed Enter key in minuteField 0 button or key, method 1 02 else if ( event.getSource() == minuteField ) { actionPerf med or 1 03 time.setMinute( Integer .parseInt( is invoked 1 04 event.getActionCommand() ) ); 1 05 minuteField.setT ext( "" ); 1 06 } Lines 91-113 1 7 0 Determine action Outline 68 depending on where event originated 2003 Prentice Hall, Inc. All rights reserved. 108 109 110 111 112 113 114 115 116 117 118 119 120 121 // user pressed Enter key in secondField else if ( event.getSource() == secondField ) { time.setSecond( Integer .parseInt( event.getActionCommand() ) ); secondField.setT ext( "" ); } displayTime(); // call outer class's method } // end method actionPerfor med } // end inner class ActionEventHandler } // end class TimeT estWindow Outline 69 T imeT estWindow .ja va 2003 Prentice Hall, Inc. All rights reserved. Outline 70 T imeT estWindow .ja va 2003 Prentice Hall, Inc. All rights reserved. 71 10.9 Nested Classes (cont.) Anonymous inner class Declared inside a method of a class Has no name 2003 Prentice Hall, Inc. All rights reserved. 1 // Fig. 1 0.23: TimeT estWindow2.java 2 // Demonstrating the Time class set and get methods 3 im por t java.awt.*; 4 im por t java.awt.event.*; 5 im por t javax.swing.*; 6 7 public class TimeT estWindow2 extends JFrame { 8 private Time time; 9 private JLabel hourLabel, minuteLabel, secondLabel; 1 0 private JT extField hourField, minuteField, secondField, displayField; 11 12 // constr uctor 13 public TimeT estWindow2() 1 4 { 15 // call JFrame constr uctor to set title bar string 1 6 super( "Anonymous Inner Class Demonstration" ); 1 7 1 8 time = new Time(); // create Time object 1 9 createGUI(); // set up GUI 20 registerEventHandlers(); // set up event handling 21 } 22 23 // create GUI com ponents and attach to content pane 2 4 private void createGUI() 25 { 26 Container container = getContentPane(); 27 container .setLayout( new FlowLayout() ); 28 Outline 72 T imeT estWindow .ja va 2003 Prentice Hall, Inc. All rights reserved. 29 hourLabel = new JLabel( "Set Hour" ); 30 hourField = new JT extField( 1 0 ); 3 1 container .add( hourLabel ); 32 container .add( hourField ); 33 34 minuteLabel = new JLabel( "Set minute" ); 35 minuteField = new JT extField( 1 0 ); 36 container .add( minuteLabel ); 37 container .add( minuteField ); 38 39 secondLabel = new JLabel( "Set Second" ); 40 secondField = new JT extField( 1 0 ); 41 container .add( secondLabel ); 42 container .add( secondField ); 43 44 displayField = new JT extField( 30 ); 45 displayField.setEditable( false ); 46 container .add( displayField ); 4 7 48 } // end method createGUI 49 50 // register event handlers for hourField, minuteField and secondField 5 1 private void registerEventHandlers() 52 { Outline 73 T imeT estWindow .ja va 2003 Prentice Hall, Inc. All rights reserved. 53 // register hourField event handler 74 54 hourField.addActionListener( Define anonymous inner class 55 that 56 new ActionListener() { // anonymous inner class implements ActionListener 57 T imeT estWindow .ja 58 public void actionPerfor med( ActionEvent event ) va 59 { 60 time.setHour( Integer .parseInt( 61 event.getActionCommand() ) ); Line 54 62 hourField.setT ext( "" ); Pass Action 63 displayTime(); Inner class implements method Listener to GUI 64 } actionPerformedcomponent's method of 65 ActionListener addAction 66 } // end anonymous inner class 67 Listener 68 ); // end call to addActionListener for hourField Pass ActionListener as 69 argument to GUI component's Line 56 70 // register minuteField event handler method addActionListeneranonymous Define 71 minuteField.addActionListener( inner class 72 73 new ActionListener() { // anonymous inner class 7 4 Lines 58-64 7 5 public void actionPerfor med( ActionEvent event ) Inner class implements 7 6 { 77 time.setMinute( Integer Repeat process for JTextField method .parseInt( actionPerf med or 7 8 event.getActionCommand() ) );minuteField 79 minuteField.setT ext( "" ); 80 displayTime(); Lines 71-85 8 1 } Outline Repeat process for minuteField All rights reserved. 2003 Prentice Hall, Inc. 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 } // end anonymous inner class ); // end call to addActionListener for minuteField Outline 75 T imeT estWindow .ja secondField.addActionListener( va Repeat process for JTextField secondField new ActionListener() { // anonymous inner class Line 87-101 Repeat process for public void actionPerfor med( ActionEvent event ) JT extField { secondField time.setSecond( Integer .parseInt( event.getActionCommand() ) ); secondField.setT ext( "" ); displayTime(); } } // end anonymous inner class ); // end call to addActionListener for secondField } // end method registerEventHandlers // display time in displayField public void displayTime() { displayField.setT ext( "The time is: " + time ); } 2003 Prentice Hall, Inc. All rights reserved. 110 76 111 // create TimeT estWindow2 object, register for its window events 112 // and display it to begin application's execution 113 public static void main( String args[] ) T imeT estWindow .ja 114 { va 115 TimeT estWindow2 window = new TimeT estWindow2(); 116 Line 121-129 117 // register listener for windowClosing event Declare Declare anonymous inner classanonymous 118 window .addWindowListener( inner class that extends WindowsAdapter that 119 extends to enable closing of JFrame 120 // anonymous inner class for windowClosing event WindowsAdapter to 121 new WindowAdapter() { 122 enable closing of 123 // ter minate application when user closes window JFrame 124 public void windowClosing( WindowEvent event ) 125 { 126 System.exit( 0 ); 127 } 128 129 } // end anonymous inner class 130 131 ); // end call to addWindowListener for window 132 133 window .setSize( 400, 1 05 ); 134 window .setVisible( tr ue ); 135 136 } // end main 137 2003 Prentice Hall, Inc. 138 } // end class TimeT estWindow2 All rights reserved. Outline Outline 77 T imeT estWindow .ja va 2003 Prentice Hall, Inc. All rights reserved. 78 10.9 Nested Classes (Cont.) Notes on nested classes Compiling class that contains nested class Results in separate .class file Inner classes with names can be declared as public, protected, private or package access Access outer class's this reference OuterClassName.this Outer class is responsible for creating inner class objects Nested classes can be declared static 2003 Prentice Hall, Inc. All rights reserved. 10.10 TypeWrapper Classes for Primitive Types Type-wrapper class Each primitive type has one Character, Byte, Integer, Boolean, etc. 79 Enable to represent primitive as Object Primitive types can be processed polymorphically Declared as final Many methods are declared static 2003 Prentice Hall, Inc. All rights reserved. 10.11 (Optional Case Study) Thinking About Objects: Incorporating Inheritance into the Elevator Simulation Our design can benefit from inheritance Examine sets of classes Look for commonality between/among sets Extract commonality into superclass Subclasses inherits this commonality 80 2003 Prentice Hall, Inc. All rights reserved. 81 10.11 Thinking About Objects (cont.) ElevatorButton and FloorButton Treated as separate classes Both have attribute pressed Both have operations pressButton and resetButton Move attribute and operations into superclass Button? 2003 Prentice Hall, Inc. All rights reserved. 82 FloorButton - pressed : Boolean = false + resetButton( ) : void + pressButton( ) : void ElevatorButton - pressed : Boolean = false + resetButton( ) : void + pressButton( ) : void Fig. 10.24 Attributes and operations of classes FloorButton and ElevatorButton. 2003 Prentice Hall, Inc. All rights reserved. 83 10.11 Thinking About Objects (cont.) ElevatorButton and FloorButton FloorButton requests Elevator to move ElevatorButton signals Elevator to move Neither button orders the Elevator to move Elevator responds depending on its state Both buttons signal Elevator to move Different objects of the same class They are objects of class Button Combine (not inherit) ElevatorButton and FloorButton into class Button 2003 Prentice Hall, Inc. All rights reserved. 84 10.11 Thinking About Objects (cont.) Representing location of Person On what Floor is Person when riding Elevator? Both Floor and Elevator are types of locations Share int attribute capacity Inherit from abstract superclass Location Contains String locationName representing location "firstFloor" "secondFloor" "elevator" Person now contains Location reference References Elevator when person is in elevator References Floor when person is on floor 2003 Prentice Hall, Inc. All rights reserved. 85 Location - locationName : String - capacity : Integer = 1 {frozen} # setLocationName( String ) : void + getLocationName( ) : String + getCapacity( ) : Integer + getButton( ) : Button + getDoor( ) : Door Elevator - moving : Boolean = false - summoned : Boolean = false - currentFloor : Integer - destinationFloor : Integer - travelTime : Integer = 5 + ride( ) : void + requestElevator( ) : void + enterElevator( ) : void + exitElevator( ) : void + departElevator( ) : void + getButton( ) : Button + getDoor( ) : Door Floor + getButton( ) : Button + getDoor( ) : Door Fig. 10.25 Class diagram modeling generalization of superclass Location and subclasses Elevator and Floor. 2003 Prentice Hall, Inc. All rights reserved. 86 9.23 Thinking About Objects (cont.) ElevatorDoor and FloorDoor Both have attribute open Both have operations openDoor and closeDoor Different behavior Rename FloorDoor to Door ElevatorDoor is "special case" of Door Override methods openDoor and closeDoor 2003 Prentice Hall, Inc. All rights reserved. 87 FloorDoor - open : Boolean = false ElevatorDoor - open : Boolean = false + openDoor( ) : void + closeDoor( ) : void + openDoor( ) : void + closeDoor( ) : void Fig. 10.26 Attributes and operations of classes FloorDoor and ElevatorDoor. Door - open : Boolean = false ElevatorDoor + openDoor( ) : void + closeDoor( ) : void + openDoor( ) : void + closeDoor( ) : void Fig. 10.27 Generalization of superclass Door and subclass ElevatorDoor. 2003 Prentice Hall, Inc. All rights reserved. 88 Light 2 Turns on/off 1 1 1 ElevatorShaft 1 Resets Floor 2 2 Door - open : Boolean = false + openDoor( ) : void + closeDoor( ) : void 1 Button Signals arrival - pressed : Boolean = false 0..* 1 + resetButton( ) : void + pressButton( ) : void 1 Presse 1 s Person 1 Opens/Closes 1 1 1 1 Opens Closes ElevatorDoor 1 Elevator 1 Signals to move 1 Occupies Resets Location - locationName : String - capacity : Integer = 1 {frozen} # setLocationName( String ) : void + getLocationName( ) : String + getCapacity( ) : Integer + getButton( ) : Button + getDoor( ) : Door Rings 1 2 1 Bell Fig. 10.28 Class diagram of our simulator (incorporating inheritance). 2003 Prentice Hall, Inc. All rights reserved. 89 Location - locationName : String - capacity : Integer = 1 {frozen} # setLocationName( String ) : void + getLocationName( ) : String + getCapacity( ) : Integer + getButton( ) : Button + getDoor( ) : Door Light - lightOn : Boolean = false + turnOnLight( ) : void + turnOffLight( ) : void ElevatorShaft Person - ID : Integer - moving : Boolean = true - location : Location + doorOpened( ) : void Floor + getButton( ) : Button + getDoor( ) : Door Elevator - moving : Boolean = false - summoned : Boolean = false - currentFloor : Location - destinationFloor : Location - travelTime : Integer = 5 + ride( ) : void + requestElevator( ) : void + enterElevator( ) : void + exitElevator( ) : void + departElevator( ) : void + getButton( ) : Button + getDoor( ) : Door Bell + ringBell( ) : void Button - pressed : Boolean = false + resetButton( ) : void + pressButton( ) : void Door - open : Boolean = false + openDoor( ) : void + closeDoor( ) : void ElevatorDoor + openDoor( ) : void + closeDoor( ) : void Fig. 10.29 Class diagram with attributes and operations (incorporating inheritance). 2003 Prentice Hall, Inc. All rights reserved. 90 10.11 Thinking About Objects (cont.) Implementation: Forward Engineering (Incorporating Inheritance) Transform design (i.e., class diagram) to code Generate "skeleton code" with our design Use class Elevator as example Two steps (incorporating inheritance) 2003 Prentice Hall, Inc. All rights reserved. 91 10.11 Thinking About Objects (cont.) public class Elevator extends Location { // constructor public Elevator() {} } 2003 Prentice Hall, Inc. All rights reserved. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 // Elevator .java // Generated using class diagrams 1 0.28 and 1 0.29 public class Elevator extends Location { // attributes private boolean moving; private boolean summoned; private Location currentFloor; private Location destinationFloor; private int travelTime = 5; private Button elevatorButton; private Door elevatorDoor; private Bell bell; // constr uctor public Elevator() {} // operations public void ride() {} public void req uestElevator() {} public void enterElevator() {} public void exitElevator() {} public void depar tElevator() {} Outline Elevator .java 92 2003 Prentice Hall, Inc. All rights reserved. 25 26 27 28 29 30 31 32 33 34 35 36 // method overriding getButton public Button getButton() { retur n elevatorButton; } // method overriding getDoor public Door getDoor() { retur n elevatorDoor; } } Outline Elevator .java 93 2003 Prentice Hall, Inc. All rights reserved. 10.12 (Optional) Discovering Design Patterns: Introducing Creational, Structural and Behavioral Design Patterns Three categories Creational Structural Behavioral 94 2003 Prentice Hall, Inc. All rights reserved. 95 10.12 Discovering Design Patterns (cont.) We also introduce Concurrent design patterns Used in multithreaded systems Section 16.12 Architectural patterns Specify how subsystems interact with each other Section 18.12 2003 Prentice Hall, Inc. All rights reserved. 96 Section 10.12 14.14 Creational design patterns Singleton Factory Method Structural design patterns Proxy Adapter, Bridge, Composite Behavioral design patterns Memento, State Chain of Responsibility, Command, Observer, Strategy, Template Method 18.12 Abstract Factory Decorator, Facade 22.12 Prototype Iterator Fig. 10.31 18 Gang of Four design patterns discussed in Java How to Program 5/e. 2003 Prentice Hall, Inc. All rights reserved. 97 Concurrent design Architectural patterns patterns 16.12 Single-Threaded Execution, Guarded Suspension, Balking, Read/Write Lock, Two-Phase Termination 18.12 Model-View-Controller, Layers Fig. 10.32 Concurrent design patterns and architectural patterns discussed in Java How to Program, 5/e. Section 2003 Prentice Hall, Inc. All rights reserved. 98 10.12 Discovering Design Patterns (cont.) Creational design patterns Address issues related to object creation e.g., prevent from creating more than one object of class e.g., defer at run time what type of objects to be created Consider 3D drawing program User can create cylinders, spheres, cubes, etc. At compile time, program does not know what shapes the user will draw Based on user input, program should determine this at run time 2003 Prentice Hall, Inc. All rights reserved. 99 10.12 Discovering Design Patterns (cont.) 5 creational design patterns Abstract Factory Builder Factory Method Prototype Singleton (Section 18.12) (not discussed) (Section 14.14) (Section 22.12) (Section 10.12) 2003 Prentice Hall, Inc. All rights reserved. 100 10.12 Discovering Design Patterns (cont.) Singleton Used when system should contain exactly one object of class e.g., one object manages database connections Ensures system instantiates maximum of one class object 2003 Prentice Hall, Inc. All rights reserved. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 // Singleton.java // Demonstrates Singleton design pattern public final class Singleton { // Singleton object to be returned by getSingletonInstance private static final Singleton singleton = new Singleton(); Outline 101 Singleton.java Line 10 private constructor private constructor ensures ensures only class only class Singleton can // private constr uctor prevents instantiation by clients Singleton can private Singleton() instantiate Singleton object instantiate { Singleton object System.err .println( "Singleton object created." ); } // retur n static Singleton object public static Singleton getInstance() { retur n singleton; } } 2003 Prentice Hall, Inc. All rights reserved. 1 // SingletonT est.java 2 // Attem pt to create two Singleton objects 3 4 public class SingletonT est { SingletonExampl 5 e.java 6 // r un SingletonExam ple 7 public static void main( String args[] ) Lines 13-14 8 { Create Singleton 9 Singleton firstSingleton; Create Singleton objects objects 10 Singleton secondSingleton; 11 Line 17 12 // create Singleton objects same Singleton 13 firstSingleton = Singleton.getInstance(); 14 secondSingleton = Singleton.getInstance(); Same Singleton 15 16 // the "two" Singletons should refer to same Singleton 17 if ( firstSingleton == secondSingleton ) 18 System.err .println( "firstSingleton and secondSingleton " + 19 "refer to the same Singleton object" ); 20 } 21 } Singleton object created. firstSingleton and secondSingleton refer to the same Singleton object Outline 102 2003 Prentice Hall, Inc. All rights reserved. 103 10.12 Discovering Design Patterns (cont.) Structural design patterns Describe common ways to organize classes and objects Adapter Bridge Composite Decorator Facade Flyweight Proxy (Section 14.14) (Section 14.14) (Section 14.14) (Section 18.12) (Section 18.12) (not discussed) (Section 10.12) 2003 Prentice Hall, Inc. All rights reserved. 104 10.12 Discovering Design Patterns (cont.) Proxy Allows system to use one object instead of another If original object cannot be used (for whatever reason) Consider loading several large images in Java applet Ideally, we want to see these image instantaneously Loading these images can take time to complete Applet can use gauge object that informs use of load status Gauge object is called the proxy object Remove proxy object when images have finished loading 2003 Prentice Hall, Inc. All rights reserved. 105 10.12 Discovering Design Patterns (cont.) Behavioral design patterns Model how objects collaborate with one another Assign responsibilities to algorithms 2003 Prentice Hall, Inc. All rights reserved. 106 10.12 Discovering Design Patterns (cont.) Behavioral design patterns Chain-of-Responsibility Command Interpreter Iterator Mediator Memento Observer State Strategy Template Method Visitor (Section 14.14) (Section 14.14) (not discussed) (Section 22.12) (not discussed) (Section 10.12) (Section 14.14) (Section 10.12) (Section 14.14) (Section 14.14) (not discussed) 2003 Prentice Hall, Inc. All rights reserved. 107 10.12 Discovering Design Patterns (cont.) Memento Allows object to save its state (set of attribute values) Consider painting program for creating graphics Offer "undo" feature if user makes mistake Returns program to previous state (before error) History lists previous program states Originator object occupies state e.g., drawing area Memento object stores copy of originator object's attributes e.g., memento saves state of drawing area Caretaker object (history) contains references to mementos e.g., history lists mementos from which user can select 2003 Prentice Hall, Inc. All rights reserved. 108 10.12 Discovering Design Patterns (cont.) State Encapsulates object's state Consider optional elevator-simulation case study Person walks on floor toward elevator Use integer to represent floor on which person walks Person rides elevator to other floor On what floor is the person when riding elevator? 2003 Prentice Hall, Inc. All rights reserved. 109 10.12 Discovering Design Patterns (cont.) State We implement a solution: Abstract superclass Location Classes Floor and Elevator extend Location Encapsulates information about person location Each location has reference to Button and Door Class Person contains Location reference Reference Floor when on floor Reference Elevator when in elevator 2003 Prentice Hall, Inc. All rights reserved.
Find millions of documents here - Study Guides, Homework Solutions, Papers, Exam Answer Keys and more.
Course Hero has millions of course related materials that will enable you to learn better,
faster and get an A in all your courses.
Below is a small sample set of documents:
Below is a small sample set of documents:
Madonna >> CSC >> 3350 (Fall, 2009)
Chapter 11 Strings and Characters Outline 11.1 Introduction 11.2 Fundamentals of Characters and Strings 11.3 Class String 11.3.1 String Constructors 11.3.2 String Methods length, charAt and getChars 11.3.3 Comparing Strings 11.3.4 Locatin...
Madonna >> CSC >> 3350 (Fall, 2009)
Chapter 13 - Graphical User Interface Components: Part 1 Outline 13.1 13.2 13.3 13.4 13.5 13.6 13.7 13.8 13.9 13.10 13.11 13.12 13.13 13.14 Introduction Overview of Swing Components JLabel Event Handling TextFields How Eve...
Madonna >> CSC >> 3350 (Fall, 2009)
Outline 14.1 14.2 14.3 14.4 14.5 14.6 14.7 14.8 14.9 14.10 14.11 14.12 14.13 Chapter 14 Graphical User Components Part 2 Introduction JTextArea Creating a Customized Subclass of JPanel JPanel Subclass that Handles Its Own ...
San Diego State >> ART >> 448 (Spring, 2008)
Michelle Garcia 241 Graphic Design I Spring 2009 For this project, we each had to come up with a narrative and successfully portray that narrative using either points, lines, or planes. My objective for this project is to clearly and cohesively conve...
San Diego State >> ART >> 448 (Spring, 2008)
Michelle Garcia 241 Graphic Design I Spring 2009 For this project, we each had to come up with a narrative and successfully portray that narrative using either points, lines, or planes. My objective for this project is to clearly and cohesively conv...
San Diego State >> ART >> 448 (Spring, 2008)
falling from the sky Michelle Garcia 241 Graphic Design I Spring 2009 Michelle Garcia ...
San Diego State >> ART >> 448 (Spring, 2008)
Table of Contents 1 . Design Brief 2 . Research 3 . Step 1 4 . Step 2 5 . Step 3 ...
San Diego State >> ART >> 448 (Spring, 2008)
...
San Diego State >> ART >> 448 (Spring, 2008)
Transitional Composition with Points, Lines, and Planes \"freefall\" Michelle Garcia 241 Graphic Design I Wendy Shapiro Spring 2009 ...
San Diego State >> ART >> 448 (Spring, 2008)
241_Project 3_Michelle Garcia principle(s): symmetry illusion pos/neg space rhythm (value) principle(s): emphasis continuation illusion unity (scale) principle(s): pos/neg space asymmetry proximity illusion (value) principle(s): illusion (scale) ...
San Diego State >> ART >> 448 (Spring, 2008)
241_Project 3_Michelle Garcia principle(s): symmetry illusion pos/neg space rhythm (value) principle(s): emphasis continuation illusion unity (scale) principle(s): pos/neg space asymmetry proximity illusion (value) principle(s): illusion (scale) ...
San Diego State >> ART >> 448 (Spring, 2008)
241_Project 3_Michelle Garcia principle(s): symmetry illusion pos/neg space rhythm (value) principle(s): emphasis continuation illusion unity (scale) principle(s): pos/neg space asymmetry proximity illusion (value) principle(s): illusion (scale) ...
San Diego State >> ART >> 448 (Spring, 2008)
241_Project 3_Michelle Garcia principle(s): symmetry illusion pos/neg space rhythm (value) principle(s): emphasis continuation illusion unity (scale) principle(s): pos/neg space asymmetry proximity illusion (value) principle(s): illusion (scale) ...
San Diego State >> ART >> 448 (Spring, 2008)
241_Project 3_Michelle Garcia principle(s): symmetry illusion pos/neg space rhythm (value) principle(s): emphasis continuation illusion unity (scale) principle(s): pos/neg space asymmetry proximity illusion (value) principle(s): illusion (Scale) ...
San Diego State >> ART >> 448 (Spring, 2008)
241_Project 3_Michelle Garcia principle(s): symmetry illusion pos/neg space rhythm (value) principle(s): emphasis continuation illusion unity (scale) principle(s): pos/neg space asymmetry proximity illusion (value) principle(s): illusion (Scale) ...
San Diego State >> ART >> 448 (Spring, 2008)
241_Project 3_Michelle Garcia principle(s): continuation illusion (value) pos/neg soace proximity principle(s): empahsis continuation illusion (scale) assymetry principle(s): symmetry proximity rhythm principle(s): unity asymmetry emphasis princ...
San Diego State >> ART >> 448 (Spring, 2008)
241_Project 3_Michelle Garcia principle(s): continuation illusion (value) pos/neg soace proximity principle(s): empahsis continuation illusion (scale) assymetry principle(s): symmetry proximity rhythm principle(s): unity asymmetry emphasis princ...
San Diego State >> ART >> 448 (Spring, 2008)
241_Project 3_Michelle Garcia principle(s): continuation illusion (value) pos/neg soace proximity principle(s): empahsis continuation illusion (scale) assymetry principle(s): symmetry proximity rhythm principle(s): unity asymmetry emphasis princ...
San Diego State >> ART >> 448 (Spring, 2008)
241_Project 3_Michelle Garcia principle(s): continuation illusion (value) pos/neg soace proximity principle(s): empahsis continuation illusion (scale) assymetry principle(s): symmetry proximity rhythm principle(s): unity asymmetry emphasis princ...
San Diego State >> ART >> 448 (Spring, 2008)
A B C (misstep) a walk) (going for (daydreaming) (freefall) ready for work) (taking off) (getting (eureka) (snail coming out of shell after rain) (a special embrace) 241_Project 3_Michelle Garcia 241_Project 3_Michelle Garcia 241_Project 3_Mich...
San Diego State >> ART >> 448 (Spring, 2008)
A B C (misstep) a walk) (going for (daydreaming) (freefall) ready for work) (taking off) (getting (eureka) (snail coming out of shell after rain) (a special embrace) 241_Project 3_Michelle Garcia 241_Project 3_Michelle Garcia 241_Project 3_Mich...
ESF >> EFB >> 502 (Fall, 2009)
...
ESF >> EFB >> 502 (Fall, 2009)
...
San Diego State >> ART >> 448 (Spring, 2008)
241_Project 3_Sarah Williams principle(s): illusion (value), continuation principle(s): symmetry principle(s): unity, illusion (value) principle(s): focal point, pos/neg space principle(s): asymmetry principle(s): unity, rhythm ...
San Diego State >> ART >> 448 (Spring, 2008)
241_Project 3_Sarah Williams principle(s): prosimity principle(s): principle(s): asymmetry, prosimity principle(s): illusion (value) principle(s): illusion (scale) principle(s): unity, rhythm, continuation ...
San Diego State >> ART >> 448 (Spring, 2008)
241_Project 3_Sarah Williams principle(s): proximity principle(s): illusion (value) principle(s): unity, illusion (value) principle(s): proximity, asytry principle(s): asymmetry principle(s): symmetry, unity ...
San Diego State >> ART >> 448 (Spring, 2008)
241_Project 3_Sarah Williams principle(s): proximity principle(s): symmetry, unity principle(s): illusion (value), symmetry, focal point principle(s): illusion (value), symmetry , focal point principle(s): illusion (scale) principle(s): unity, ...
San Diego State >> ART >> 448 (Spring, 2008)
241_Project 3_Sarah Williams principle(s): proximity principle(s): proximity, symmetry principle(s): unity, illusion (value) principle(s): proximity, asymmetry principle(s): asymmetry principle(s): symmetry, unity ...
San Diego State >> ART >> 448 (Spring, 2008)
241_Project 3_Sarah Williams principle(s): proximity principle(s): unity, illusion (value) principle(s): illusion (value) principle(s): focal point, pos/neg space principle(s): continuation principle(s): symmetry, unity ...
Oregon State >> BA >> 160 (Fall, 2009)
Entrepreneurship 1 Entrepreneurship: A Field- And An Activity \"Much of our American progress has been the product of the individual who had an idea; pursued it; fashioned it; tenaciously clung to it against all odds; and then produced it, sold it ...
Oregon State >> BA >> 160 (Fall, 2009)
Entrepreneurship 2 Uncovering Opportunities: Understanding Entrepreneurial Opportunities and Industry Analysis \"In great affairs we ought to apply ourselves less to creating chances than to profiting from those that offer.\" -La Rouchefoucauld, Max...
Oregon State >> BA >> 160 (Fall, 2009)
Entrepreneurship 3 Cognitive Foundations of Entrepreneurship: Creativity and Opportunity Recognition \"When written in Chinese the word crisis is composed of two characters. One represents danger and the other represents opportunity.\" -John F. Kenn...
Oregon State >> BA >> 160 (Fall, 2009)
Entrepreneurship 5 Assembling the Team: Acquiring and Utilizing Essential Human Resources \"Union may be strength, but it is mere blind brute strength unless wisely directed.\" -Samuel Butler, 1882 5-2 Human Resources Knowledge Skills Talents...
University of Illinois, Urbana Champaign >> FIN >> 361 (Fall, 2009)
Investments Overview Chapter 1 Objectives What is an investment? What are the general steps in the investment process? Decisions to be made Overview of markets Participants and types of markets Investments Commitment of current resource...
University of Illinois, Urbana Champaign >> FIN >> 361 (Fall, 2009)
Outline for today Overview of Financial Assets Chapter 2 Give an introduction to various financial securities Most will be covered in more detail later in the course After today, you should be able to read most of the quotes in the WSJ Money mar...
University of Illinois, Urbana Champaign >> FIN >> 361 (Fall, 2009)
Overview Selling / Trading Securities Chapter 3 How do firms issue securities? How does trading occur on the exchanges? OTC? What are the mechanics of buying shares on margin? How can we make money if we think stock prices will decline? What reg...
University of Illinois, Urbana Champaign >> FIN >> 361 (Fall, 2009)
Overview Risk and Return Chapter 6 #1,2,3,6,9,11,15 Begin to construct the best portfolio for an investor Need to consider risk and return measures for individual securities and a portfolio Look at measures of risk and return Historical performan...
University of Illinois, Urbana Champaign >> FIN >> 361 (Fall, 2009)
Overview Investment companies and Mutual Funds Chapter 4 #2-4, 6-8, 13 Why would we consider letting others manage our money? What types of investment companies are available to us? How do we determine returns when invested in mutual funds? How g...
University of Illinois, Urbana Champaign >> FIN >> 361 (Fall, 2009)
Overview Valuing Options Chapter 17 #2,3,5,6,7,8,19,22 What variables affect stock prices? How can we develop prices for call options and put options? Binomial trees Black-Scholes Intrinsic and Time Value We saw that intrinsic value is the payo...
University of Illinois, Urbana Champaign >> FIN >> 361 (Fall, 2009)
Most Correlated 1.07% 1.07% 1.07% 1.07% 1.07% Expected Return 1.06% 1.06% 1.06% 1.06% 1.06% 1.06% 1.06% 4.00% 4.20% 4.40% 4.60% Standard Deviation 4.80% 5.00% 5.20% Least Correlated 3.00% 2.50% 2.00% Expected Return 1.50% 1.00% 0.50% 0.0...
University of Illinois, Urbana Champaign >> FIN >> 361 (Fall, 2009)
Sheet2 Date 30-Jun-1991 31-Jul-1991 31-Aug-1991 30-Sep-1991 31-Oct-1991 30-Nov-1991 31-Dec-1991 31-Jan-1992 29-Feb-1992 31-Mar-1992 30-Apr-1992 31-May-1992 30-Jun-1992 31-Jul-1992 31-Aug-1992 30-Sep-1992 31-Oct-1992 30-Nov-1992 31-Dec-1992 31-Jan-199...
Michigan >> MVS >> 110 (Fall, 2009)
Lecture 4: Reflexes and Spinal Circuits Afferent pathway Sensory systems CNS Efferent pathway Movement Reflex. sA simple neural circuit example of sensory and motor systems. s Involuntary action or movement that occurs in response to a stimulu...
Michigan >> MVS >> 442 (Winter, 2009)
63 Chapter 3 Receptors and chemical message transduction Interpretation of studies in exercise physiology that employ hormone (H) measurements or pharmacological agents that modify H release or action requires an understanding of the characteristic...
Michigan >> MVS >> 443 (Fall, 2009)
Regulation of the skeletal mass through the life span Functions of the skeletal system Mechanical protection skull leverage for muscles calcium store red blood cells in bone marrow Movement Mineral metabolism Erythropoiesis Changes in the...
Michigan >> MVS >> 443 (Fall, 2009)
Regulation of the skeletal mass through the life span 9/30/1999 Functions of the skeletal system n Mechanical protection skull n Movement leverage for muscles n Mineral metabolism calcium store n Erythropoiesis red blood cells in bone ma...
Michigan >> MVS >> 443 (Fall, 2009)
Osteoporosis Reparative growth of the bone bone is continuously remodeled internal remodeling (no change in shape) endosteal resorption for metabolic maintenance for repair of fatigue damage Bone formation is in excess of bone resorption du...
Michigan >> MVS >> 443 (Fall, 2009)
Health benefits of cognitive stimulation Cognitive function and aging Types of cognitive deterioration with age decline in verbal memory reduced fine motor skills decline in executive control functions associated with prefrontal and frontal cor...
Michigan >> MVS >> 443 (Fall, 2009)
Health benefits of cognitive stimulation Cognitive function and aging w Types of cognitive deterioration with age decline in verbal memory reduced fine motor skills decline in executive control functions associated with prefrontal and frontal co...
Michigan >> INTRO >> 443 (Fall, 2009)
Welcome to MVS443! While we are waiting for all the students to arrive, please make a name tag for yourself , fill out a short questionnaire, All about you! and take a copy of syllabus. You will find these on the desk. Thank you. Katarina Borer MVS...
Michigan >> MVS >> 443 (Fall, 2009)
The neuroendocrine growth hormone clock and body mass Are we programmed to grow to a certain size, to stop growing and to decay? What is growth? Growth is the process through which the nutrient energy is assimilated into structural components of th...
Michigan >> MVS >> 443 (Fall, 2009)
Micronutrient intake and deficiencies in the aged Nutritional needs of the aged s s s s Sensory changes that compromise nutrient detection Physiological changes that compromise nutrient transit and absorption Behavioral patterns that lead to malnu...
Michigan >> MVS >> 443 (Fall, 2009)
Micronutrient intake and deficiencies in the aged Nutritional needs of the aged n Sensory changes that compromise nutrient detection n Physiological changes that compromise nutrient transit and absorption n Behavioral patterns that lead to malnutri...
Michigan >> MVS >> 443 (Fall, 2009)
The somatopause What stops our growth and diminishes GH secretion? What extends or stops statural growth? Statural growth is extended if the early growth rate is slowed underfed adolescents grow for a longer time until they attain a \"critical body...
Michigan >> MVS >> 443 (Fall, 2009)
Aging of the biological rhythms and autonomic function Function of biological rhythms Pattern secretion of most hormones Structure our sleep-wake pattern Control of breathing circulation heart beat blood pressure Affect mental health circad...
Michigan >> MVS >> 443 (Fall, 2009)
Part 3:Strategies for successful aging Avoiding disease with dietary supplements: Vitamins and antioxidants Causes of disability and disease with aging Causes of death for old individuals Atherosclerosis (CHD) CNS-vascular accidents (stroke) Ca...
Michigan >> MVS >> 443 (Fall, 2009)
Part 3:Strategies for successful aging Avoiding disease with dietary supplements: Vitamins and antioxidants Causes of disability and disease with aging Causes of death for old individuals Atherosclerosis (CHD) CNS-vascular accidents (stroke) Ca...
Michigan >> MVS >> 443 (Fall, 2009)
Obesity in aging: Hormonal contribution Hormonal issues in obesity and aging x x x x x Hormonal role in regulation of energy balance Genetic component in hormonal regulation Life style contribution to hormonal changes Age-associated hormonal changes...
Michigan >> MVS >> 443 (Fall, 2009)
Part 3:Strategies for successful aging Avoiding disease with physical activity Causes of disability and disease with aging Causes of death for old individuals Atherosclerosis (CHD) CNS-vascular accidents (stroke) Cancer Hypertension Accidents ...
Michigan >> MVS >> 443 (Fall, 2009)
Part 3:Strategies for successful aging Avoiding disease with physical activity Causes of disability and disease with aging Causes of death for old individuals Atherosclerosis (CHD) CNS-vascular accidents (stroke) Cancer Hypertension Accidents...
Michigan >> MVS >> 443 (Fall, 2009)
Stress and the aging brain Part 2 Stress and the aging brain Acute stress catecholamines cardiovascular manifestations gastrointestinal manifestations Chronic stress HPA axis cortisol as a neurotoxic agent DHEA as neuroprotective agent ...
Bucknell >> JDK >> 304 (Fall, 2009)
Introduction to Statistical Thought Michael Lavine August 3, 2008 i Copyright c 2005 by Michael Lavine C ONTENTS List of Figures List of Tables Preface 1 Probability 1.1 Basic Probability . . . . . . . . . . . . . . . 1.2 Probability Densities . . ...
SIU Edwardsville >> CS >> 482 (Fall, 2008)
./models/fairy.nmb / fairy model and flirt anim ./models/branch.nmb / the branch ./models/sunning.nmb / sunning animation 1024 768 / Window width/height 32 24 0 / color / z / stencil depth 0 ...
Wisconsin >> CS >> 412 (Fall, 2008)
Notes on Homework 2 Problems for cs412 Problem 1: You need to submit the MATLAB file(s) you used to verify your solutions correctness. The pdf should contain the outputs of your MATLAB runs and the full polynomial approximation justified with MATLAB...
Minnesota >> ECON >> 1101 (Fall, 2008)
University of Minnesota Econ 1101: Principles of Microeconomics Lecture Section 004 Summer 2004 (7/12/2004-8/6/2004) Lecture: 09:00 - 12:00 MTWThF (7/12/2004-8/6/2004), BlegH 145 Instructors: Jaromir Nosal (1st half), Li Jinxiong (2nd half) Jaromir N...
Minnesota >> ECON >> 3101 (Fall, 2008)
Homework Assignment 1 Econ 3101, Section 004 Due September 20, in class 1. Question 2.1 a) - e) from page 58 of the book. 2. Question 2.3 from page 59 of the book. 3. Question 2.4 from page 59 of the book. 4. Question 2.7 from page 60 of the book. 5....
San Diego State >> ART >> 448 (Spring, 2008)
...
San Diego State >> ART >> 448 (Spring, 2008)
...
San Diego State >> ART >> 448 (Spring, 2008)
x x x x x 241_Graphic Design I : Spring 09 : Chanelle Villanueva 3 3 3 3 3 x x x x x 3 3 3 3 3 x x x x x ...
San Diego State >> ART >> 448 (Spring, 2008)
x 3 x 3 x 241_Graphic Design I : Spring 09 : Chanelle Villanueva 3 2 3 2 3 x 3 x 3 x 3 2 3 2 3 x 3 x 3 x ...
San Diego State >> ART >> 448 (Spring, 2008)
3 4 2 3 4 241_Graphic Design I : Spring 09 : Chanelle Villanueva x 2 1 2 x 3 4 2 3 4 x 2 x 2 x 3 4 2 3 4 ...
What are you waiting for?