Understanding Object-Oriented Programming Concepts in Java
Clear up confusion on method order, printing variables from other classes, use of "this.xxx," dealing with unnecessary decimal points, object vs. address understanding, syntax preferences, calling methods, private vs. public methods, return types in UML diagrams, and other key OOP concepts.
Download Presentation
Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
E N D
Presentation Transcript
SE1011 Week 6, Class 2 Today Return Half Exam 2 (cont.) Object Oriented Programming (cont.) UML class diagrams Muddiest Point Next Half Exam: Week 7, Monday SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder 1
Old Muddy Points I'm a bit confused about the order in which methods are used. How to print the variables from another class when to use "this.xxx" When would we want unnecessary decimal points? (# instead of 0) I getting confused between objects and addresses and the actual clock code I would like to know if there are any syntax choice preferences you have that you would like us to use. How to call an output from a class? calling methods returning values this DecimalFormat memory & code syntax returning values? Key: bold discussed this class; italics discussed at start; underline discussed in lecture 2
Muddiest Point (1) what is "static"? I like that UML states clearly the methods and variables we are using. I only got confused in the last 10 mins of class how to know when to make it public or private and also how to know if it is void or otherwise. In the UML diagram, for methods when the return is not void, do we specify the type that is returned or the variable that is returned? static - later memory diagrams public/private, returning values UML: returning values UML. Yes, but there are many forms Yes - See BigInteger and BigDecimal Is UML basically a universal pseudocode? bigger value than long? Key: bold discussed this class; italics discussed at start; underline discussed in lecture 3
Muddiest Point (2) how to print variables from other classes How do you know when to use a private method? Should you just know or do you come back and find out later? scope of variables between classes Would two references to the same object ever be useful in main? Some of the PPT layout slides where the variables and methods are laid out are confusing. The actual java code makes more sense to me timing returning values public/private public/private No - not yet memory diagrams ? Key: bold discussed this class; italics discussed at start; underline discussed in lecture 4
Scope A variable's scope is where it is visible This is determined by local / instance (local only visible in method) life of variable (local only "lives" to end of block) public / private (instance only visible in class unless public) SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder 5
How to add culture to incubator? main( ) 285638 Point A cupsCulture numBacteria 0.125 0 double long incubator Incubator 285638 Incubator ref In YogurtDriver's main( ) Incubator incubator = new Incubator(); // Point A incubator.addStarterCups((double)1/8); SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder 6
How to add culture to incubator? main( ) 285638 Point B addStarterCups( ) this cupsCulture numBacteria 285638 0.125 0 Incubator ref starterCups double long 0.125 incubator Incubator double 285638 Incubator ref inIncubator'saddStarterCups( ) // Point B long newBacteria = (long)(starterCups * BACTERIA_PER_CUP_STARTER SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder 7
How to add culture to incubator? main( ) 285638 Point C addStarterCups( ) this cupsCulture numBacteria 285638 0.125 0 Incubator ref starterCups double long 0.125 incubator Incubator double 285638 newBacteria 2_500_000_000 Incubator ref long inIncubator'saddStarterCups( ) long newBacteria = (long)(starterCups * BACTERIA_PER_CUP_STARTER // Point C numBacteria += newBacteria; SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder 8
How to add culture to incubator? main( ) 285638 Point D addStarterCups( ) this cupsCulture numBacteria 285638 0.125 2_500_000_000 Incubator ref starterCups double long 0.125 incubator Incubator double 285638 newBacteria 2_500_000_000 Incubator ref long inIncubator'saddStarterCups( ) numBacteria += newBacteria; // Point D SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder 9
How to print a class variable? main( ) 285638 Point E cupsCulture numBacteria 0.125 2_500_000_000 double long incubator Incubator 285638 Incubator ref In YogurtDriver's main( ) incubator.addStarterCups((double)1/8); // Point E SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder 10
How to print a class variable? main( ) 285638 Point F getNumBacteria( ) cupsCulture numBacteria 0.125 2_500_000_000 double long Complete this part. Also, what value is returned? incubator Incubator 285638 Incubator ref inIncubator'sgetNumBacteria() // Point F return numBacteria; SE1011 Week 6, Class 2 SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder 11
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder 12
Acknowledgement This course is based on the text Introduction to Programming with Java by Dean & Dean, 2nd Edition SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder 13