CMPE212 – Stuff… Assn 2 due next Friday. Winter 2018

Slides:



Advertisements
Similar presentations
Composition CMSC 202. Code Reuse Effective software development relies on reusing existing code. Code reuse must be more than just copying code and changing.
Advertisements

16-Jun-15 javadoc. 2 Javadoc placement javadoc comments begin with /** and end with */ In a javadoc comment, a * at the beginning of the line is not part.
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
Winter 2006CISC121 - Prof. McLeod1 Last Time Misc. useful classes in Java: –String –StringTokenizer –Math –System.
Documentation javadoc. Documentation not a programmer's first love lives in a separate file somewhere usually a deliverable on the schedule often not.
Java Doc Guideline R.SANTHANA GOPALAN. Java Doc Guideline Audience Internal Developers PQA - who write test plans PPT – who write the documentation Customers.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Today: –Review declaration, implementation, simple class structure. –Add an exception class and show.
Winter 2006CISC121 - Prof. McLeod1 Stuff We had better discuss a midterm date… –27 Feb. to 3 March or –6 to 10 March.
Today… Modularity, or Writing Functions. Winter 2016CISC101 - Prof. McLeod1.
Quiz 3 Topics Functions – using and writing. Lists: –operators used with lists. –keywords used with lists. –BIF’s used with lists. –list methods. Loops.
Today Javadoc. Packages and static import. Viewing API source code. Upcoming Topics: –protected access modifier –Using the debugger in Eclipse –JUnit testing.
Today Review passing by reference and pointers. null pointers. What is an Object? Winter 2016CMPE212 - Prof. McLeod1.
Notices Assn 2 is due tomorrow, 7pm. Moodle quiz next week – written in the lab as before. Everything up to and including today’s lecture: Big Topics are.
Today Encapsulation. Build a fully encapsulated Halloween class, going from Halloween1 to Halloween6 (eventually!): –The final version will have overloaded.
Today… StringTokenizer class. Method Overloading. Catching Exceptions (and what they are!). Start Pointers and Aliasing. Winter 2016CMPE212 - Prof. McLeod1.
Notices Assn 2 is due Friday, 7pm. Moodle quiz next week – written in the lab as before. Everything up to and including Thursday’s lecture: Big Topics.
Winter 2006CISC121 - Prof. McLeod1 Stuff Midterm exam in JEF234 on March 9th from 7- 9pm.
CISC124 - Notices Assn 2 due this Friday. You already know what you need to do this assignment: –Another procedural program. –Uses text file I/O (see Exercise.
Advanced Programing practices
More Sophisticated Behavior
Chapter 3: Using Methods, Classes, and Objects
Winter 2018 CMPE212 9/18/2018 CMPE212 – Stuff…
Fall 2017 CISC124 9/18/2018 CISC124 First onQ quiz this week – write in lab. More details in last Wednesday’s lecture. Repeated: The quiz availability.
CMPE212 – Stuff… Assn 3 due and Quiz 2 in the lab next week.
Winter 2018 CMPE212 9/21/2018 CMPE212 – Stuff…
Fall 2017 CISC124 9/21/2018 CISC124 First onQ quiz this week – write in lab. More details in last Wednesday’s lecture. Repeated: The quiz availability.
CMPE212 – Stuff… Exercises 4, 5 and 6 are all fair game now.
Introduction to javadoc
Winter 2018 CMPE212 11/12/2018 CMPE212 – Stuff…
CISC124 Assignment 4 on Inheritance due next Monday, the 12th at 7pm.
CISC124 Assignment 4 on Inheritance due next Monday, the 12th at 7pm.
CISC124 Assignment 4 on Inheritance due next Monday, the 12th at 7pm.
CISC124 Quiz 1 marking nears completion!
CMPE212 – Stuff… Assn 2 due this Friday. Winter 2018
CISC101 Reminders Assn 3 due Friday, this week. Quiz 3 next week.
Fall 2018 CISC124 12/1/2018 CISC124 Note that the next assignment, on encapsulation, is due next Wednesday at 7pm – not Friday. The next Quiz is not until.
Fall 2018 CISC124 12/3/2018 CISC124 or talk to your grader with questions about assignment grading. Fall 2018 CISC124 - Prof. McLeod Prof. Alan McLeod.
CISC101 Reminders Quiz 2 graded. Assn 2 sample solution is posted.
CISC101 Reminders Assn 3 due tomorrow, 7pm.
CISC/CMPE320 - Prof. McLeod
CISC124 Assignment 3 due tomorrow at 7pm.
Defining Classes and Methods
CISC124 Assignment 4 on Inheritance due next Friday.
JavaDoc and Contracts Fall 2008.
Fall 2018 CISC124 2/1/2019 CISC124 Note that the next assignment, on encapsulation, is due next Wednesday at 7pm – not Friday. The next Quiz is not until.
CISC/CMPE320 - Prof. McLeod
Fall 2018 CISC124 2/22/2019 CISC124 Quiz 1 This Week. Topics and format of quiz in last Tuesday’s notes. The prof. (me!) will start grading the quiz.
CISC/CMPE320 - Prof. McLeod
CISC/CMPE320 - Prof. McLeod
CISC/CMPE320 - Prof. McLeod
Advanced Programing practices
Fall 2018 CISC124 2/24/2019 CISC124 Quiz 1 marking is complete. Quiz average was about 40/60 or 67%. TAs are still grading assn 1. Assn 2 due this Friday,
CISC124 Assignment 3 sample solution will be posted tonight after 7pm.
Introduction to javadoc
Winter 2019 CMPE212 4/5/2019 CMPE212 – Reminders
CMPE212 – Reminders Assignment 2 sample solution is posted.
CMPE212 – Reminders Assignment 3 due next Friday.
CISC101 Reminders Assignment 3 due next Friday. Winter 2019
Winter 2019 CISC101 4/29/2019 CISC101 Reminders
CMPE212 – Reminders Quiz 1 marking underway. Assignment 1 due today.
CMPE212 – Reminders Assignment 2 due this Friday.
CMPE212 – Reminders Quiz 1 marking done. Assignment 2 due next Friday.
Winter 2019 CMPE212 5/3/2019 CMPE212 – Reminders
Winter 2019 CMPE212 5/10/2019 CMPE212 – Reminders
CMPE212 – Reminders Assignment 2 due in a week.
CMPE212 – Reminders Assignment 2 due today, 7pm.
Winter 2019 CMPE212 5/25/2019 CMPE212 – Reminders
CISC101 Reminders Assignment 3 due today.
CMPE212 – Reminders Assignment 2 due next Friday.
CMPE212 – Reminders Assignment 4 on Inheritance due next Friday.
Presentation transcript:

CMPE212 – Stuff… Assn 2 due next Friday. Winter 2018 Winter 2018 CMPE212 9/19/2018 CMPE212 – Stuff… Assn 2 due next Friday. Winter 2018 CMPE212 - Prof. McLeod Prof. Alan McLeod

Today Encapsulation, Cont. Look over Halloween5 again. Javadoc. WaiterData – another Encapsulation Example. Winter 2018 CMPE212 - Prof. McLeod

An Example, Cont. It would be easier to design a Class that contains (or encapsulates) these four fields and then design another class to collect instances of this Class. No way the fields could get out of sync since moving a record moves all fields at once. Collection record 1 record 2 temp array year record 3 record 4 number record 5 condition record 6 .... Winter 2018 CMPE212 - Prof. McLeod

Halloween5 Same structure as Halloween4, but has fixed the weather mutator and implemented two interfaces: Comparable<Halloween5> This is a generic interface that allows this object to be sorted with sort methods built into Java. Serializable This allows this object to be saved directly to a file. (Both of these are used in Assignment 3.) Winter 2018 CMPE212 - Prof. McLeod

Aside – What is an Interface? An interface is a totally abstract class – none of the methods in the class are implemented – they don’t contain any concrete code. (Weird!) Instead of doing something – an interface acts as a design specification and can be used as a type. A class that implements an interface promises to have concrete versions of all the abstract methods in the interface. More on these little beasties later. Winter 2018 CMPE212 - Prof. McLeod

Halloween5, Cont. See the changes in Halloween5. See TestHalloween5.java for tests that focus on what the interface implementations allow us to do with this class that we could not do with Halloween4. Winter 2018 CMPE212 - Prof. McLeod

Aside – The serialVersionUID Thing This is a unique code ID value that is used to identify your object. Auto-generation uses various aspects of the structure of your class to generate this value. If you change the structure, you will need to re-generate this number. It is saved with the contents of your object in the file (“serialized”). When you read the object (“deserialize”) the number is compared to the number stored in the class to make sure the cast will work. Winter 2018 CMPE212 - Prof. McLeod

Variations on a Theme… This standard encapsulated class structure is followed by every class in Java. Some classes don’t need all the pieces. For example: Attributes but no mutators. (Immutable) No attributes – then you don’t need constructors, mutators or accessors. (This class is probably just composed of utility methods, maybe all static.) An object that will never be part of a collection – you might not need equals() or compareTo(). A class that just has a main method. This is just the starting point of a program – possibly no other methods are required. Winter 2018 CMPE212 - Prof. McLeod

More Variations Of course, a class may need more methods than those we have discussed. Think of the additional behaviour that will be useful to the user of your object. A majority of methods should have something to do with the attributes of the object. But you might add a few static methods if you cannot think of anywhere else to put them (the wrapper classes are like this…). Winter 2018 CMPE212 - Prof. McLeod

Fall 2013 CMPE212 Javadoc Javadoc.exe is a program that comes with the JDK. (It is in the same directory as javac.exe and java.exe – the “bin” folder). It is not included in the JRE only. If I have written a class, “MyClass.java”, that contains properly formatted comments (more below), then running “javadoc MyClass.java” generates a file “MyClass.html”. The html file contains external documentation generated from the formatted comments in the source code. Winter 2018 CMPE212 - Prof. McLeod Prof. Alan McLeod

Javadoc - Cont. Normal block comments in Java are delimited by “/*” and “*/”. Everything between these delimiters, usually multiple lines, is a comment. Javadoc block comments are delimited by “/**” and “*/”. Winter 2018 CMPE212 - Prof. McLeod

Javadoc - Cont. The general form of a Javadoc comment: /** * Summary sentence. * More general information about the * class, attribute or method which * follows the comment, using as many lines * as necessary. (html tags can be included) * * javadoc tags to specify more specific * information, such as parameters and * return values for a method */ Winter 2018 CMPE212 - Prof. McLeod

Javadoc - Cont. The general form of a Javadoc tag is: @tagName comment The tags you use depend on what you are describing (class, method or attribute). In the case of methods, you can have a tag for each parameter, the return value, and a tag for each thrown exception. Eclipse (really nice!!) will generate a blank tag for you after you type “/**”. Typically, you will only write javadoc comments for public attributes and methods… Winter 2018 CMPE212 - Prof. McLeod

Eclipse Javadoc Assist For example, if you have the method header: public static double[] generateRandomArray(int size) Type /** right above this line and press <enter>. You will get: /** * * @param size * @return */ Winter 2018 CMPE212 - Prof. McLeod

Eclipse Javadoc Assist, Cont. Then you have to finish the comment: /** * Generates an array of random doubles. * * The method uses the Math.random() method to generate * an array of doubles between 0.0 and 1.0. * @param size The desired size of the array. * @return The array of random doubles. */ Winter 2018 CMPE212 - Prof. McLeod

Eclipse Javadoc Assist, Cont. Hold your cursor over the method header and you will get a preview of what the processed Javadoc will look like: (Or view the Javadoc tag in the same view as the Console tag.) Winter 2018 CMPE212 - Prof. McLeod

Common Javadoc Tags @param Parameter_name description @throws Exception_name description @return description @see packageName.ClassName, packageNamme.ClassName#methodName, etc. @author @version Winter 2018 CMPE212 - Prof. McLeod

Javadoc - Cont. Html tags can also be added to the comments to add more formatting to the resulting document: <em> for emphasis <code> for code font <img> for images <ul><li> </li></ul> for bulleted lists Etc… Winter 2018 CMPE212 - Prof. McLeod

Javadoc Reference The best reference for javadoc is at: http://www.oracle.com/technetwork/java/javase/documentation/index-jsp-135444.html Winter 2018 CMPE212 - Prof. McLeod

Javadoc - Cont. The output from Javadoc looks exactly like the API documentation you have already seen - since that is the way it has been generated! The advantage is that when source code is changed, the Javadoc comments can be changed in the source, at the same time. The external documentation is then easily re-generated. Javadoc also provides a consistent look and feel to these API documents. Winter 2018 CMPE212 - Prof. McLeod

Javadoc - Cont. Most modern IDE’s (like NetBeans and Eclipse) allow you to run Javadoc from within the environment, and provide tools and wizards to help you create comments. In Eclipse, select “Project”, then “Generate Javadoc…”. Let’s run javadoc on the Halloween5 class. (Note that the first time you do this, you will have to tell Eclipse where javadoc.exe resides.) Winter 2018 CMPE212 - Prof. McLeod

Another Encapsulated Example The problem on the next slide – “WaiterData” - was a quiz from several years ago (written on paper!). Let’s read over the problem and then look at the solution. This solution has some extra stuff!: Javadoc comments The exception class toString, clone, equals Winter 2018 CMPE212 - Prof. McLeod

Write the code for a mutable encapsulated class called WaiterData Write the code for a mutable encapsulated class called WaiterData. This class will use the IllegalWaiter exception, but you do not have to write this exception class – you can just assume that it already exists. (Let’s write it anyways!) WaiterData is designed to hold the daily sales for a month for a particular waiter. The class will hold two attributes, a String for the name of the waiter and an array of type double for the actual daily sales values. The String must have a length of 3 or more to be legal. The array must have a size between 5 and 31 inclusive. Each individual value in the array must lie between 0 and 500 inclusive. You may assume that neither argument will ever be null. Write a two parameter constructor for WaiterData. WaiterData must have a mutator for each attribute and must throw the IllegalWaiter exception if an attempt is made to create an illegal WaiterData object or if an attempt is made to set an attribute to an illegal value through either mutator. Write accessors for both attributes. Finally, write a compareTo() method for your WaiterData class. Comparison is based on the total amount of the sales array. If the supplied WaiterData object has had a higher sales total then return -1. Return 1 if the supplied object has lower total sales and zero of both totals are equal to within a dollar. Do not write any other public methods – you do not need a toString(), clone() or an equals() method. (Let’s write them anyways!) Winter 2018 CMPE212 - Prof. McLeod