Lecture 14 Libraries and Encapsulaton Last time 1 Parameter passing 2 Libraries 3 Public vs private Today 1 Project 3 due 10 9 2 Exam 1 coming 10 11 3 APIs comments and documentation 10 2 2006 CMSC 131 Fall 2006 Rance Cleaveland 2006 Univeristy of Maryland Project 3 Is Assigned The assignment is on the CMSC 131 web site click Projects link It is due Monday 10 9 at 11 pm The project is open Start now Read entire assignment from beginning to end before starting to code Check out assignment now from CVS Follow the instructions exactly as much of grading is automated CMSC 131 Fall 2006 Rance Cleaveland 2006 University of Maryland 1 Exam 1 Is 10 11 in Discussion Section Take the test in your own section Test will cover material since beginning of semester Test will be closed book closed neighbor Study CMSC 131 Fall 2006 Rance Cleaveland 2006 University of Maryland 2 Study When Project and test are very close to one another This is part of college What to do Start project immediately Aim to finish project by Friday Start studying for exam on Saturday even if project not yet finished You can do it CMSC 131 Fall 2006 Rance Cleaveland 2006 University of Maryland 3 More on Project Project implement a class for picture viewing Some new concepts Dialog boxes Pixels PNG JPEG GIF Picture manipulation library Do you have to know what all these mean Dialog boxes yes Picture manipulation library yes Others no CMSC 131 Fall 2006 Rance Cleaveland 2006 University of Maryland 4 Dialog Boxes Another way to get inputs besides Scanner Library cmsc131PictureLibrary contains class TextInputOutput for dialog boxes Class TextInputOutput contains method public static String simpleDialogBox String s Argument string is prompt Returned string is input provided by user CMSC 131 Fall 2006 Rance Cleaveland 2006 University of Maryland 5 Example String str TextInputOutput simpleDialogBox Enter a value System out println str foo is printed on console CMSC 131 Fall 2006 Rance Cleaveland 2006 University of Maryland 6 How Do You Find This Out By looking at the API documentation for cmsc131PictureLibrary at web site http www cs umd edu class fall2006 cmsc13 1 Projects P3 doc index html Other useful classes for project described there BasicPicture PictureUtil etc CMSC 131 Fall 2006 Rance Cleaveland 2006 University of Maryland 7 How Do You Program with New Libraries KISS Keep It Simple S d Read the documentation to identify the methods you need Write very simple programs invoking the methods Make sure you understand what the methods do Example BasicPicture pic new BasicPicture Bart jpg PictureUtil show pic CMSC 131 Fall 2006 Rance Cleaveland 2006 University of Maryland 8 APIs Recall class API Public variables Public methods What is API for new Date class see example for this lecture CMSC 131 Fall 2006 Rance Cleaveland 2006 University of Maryland 9 Copy Constructors Constructors can take arguments that are objects from the same class Date Date d This is useful for defining copy constructors e g Date Date d day d day month d month year d year separator d separator note d note Constructor creates a new object with same data as input So CMSC 131 Fall 2006 Rance Cleaveland 2006 University of Maryland 10 Example Date Range Sometimes you want to create a date range Beginning date New date some days later Date class contains method public void addDays int future Will the following work create start date of 9 27 2006 and end date one week Date start new Date 27 9 2006 Date end start end addDays 7 No start end are aliases Modifying end also modifies start CMSC 131 Fall 2006 Rance Cleaveland 2006 University of Maryland 11 Using Copy Constructor To solve range problem use copy constructor Date start new Date 27 9 2006 Date end new Date start end addDays 7 start now has value 9 27 2006 end has value 10 4 2006 CMSC 131 Fall 2006 Rance Cleaveland 2006 University of Maryland 12 Comments Explanations you add into your code Three forms in Java Put text here Put text here to end of line Put text here Last form is special comment for javadoc utility for generating documentation from comments CMSC 131 Fall 2006 Rance Cleaveland 2006 University of Maryland 13 Comments cont Some programmers hate them but they are essential for code understanding it is called code for a reason Beginning with Project 3 you will be graded on comments as well as indentation Comment Every variable what is variable for Every method what does method do Every class what is class for who wrote it CMSC 131 Fall 2006 Rance Cleaveland 2006 University of Maryland 14
View Full Document