1 / 16

Creating Classes part 4

Creating Classes part 4. Barb Ericson Georgia Institute of Technology Oct 2005. Learning Goals. Computing concepts Comments Why add comments? Types of comments How to add Javadoc comments How to preview HTML from Javadoc comments How to create HTML for all classes in a directory

lhuggins
Download Presentation

Creating Classes part 4

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Creating Classespart 4 Barb Ericson Georgia Institute of Technology Oct 2005 Georgia Institute of Technology

  2. Learning Goals • Computing concepts • Comments • Why add comments? • Types of comments • How to add Javadoc comments • How to preview HTML from Javadoc comments • How to create HTML for all classes in a directory • Creating another class • Using UML to show classes and the relationships between them Georgia Institute of Technology

  3. Comments • You should add comments to your code • To make it easier to read and change • Comments are ignored by the complier • Not added to the byte codes • Java has 3 kinds of comments • // comment ends at the end of this line • /* comment ends with next */ • /** Javadoc comment that ends with */ • can be used by the javadoc utility to create HTML documentation Georgia Institute of Technology

  4. Javadoc Comments • Add a comment before the class definition • That explains the purpose of this class • And says who wrote it • @author Barb Ericson /** * Class that describes a student. A student has a * name and an array of grades. You can get * information about a student such as her/his * name and grade average. * * @author Barb Ericson */ public class Student Georgia Institute of Technology

  5. Method Comments • Add a comment before each method • What the parameters are • @param name info • What is returned • @return info /** * Method to set the name for this student * @param theName the new name to use * @return true if success else false */ public boolean setName(String theName) Georgia Institute of Technology

  6. Previewing Javadoc HTML • Click on Tools • Click on Preview Javadoc for Current Document • This will generate the HTML from the javadoc comments and display it • The HTML document will display Georgia Institute of Technology

  7. Generating all HTML for Directory • In DrJava click on the Javadoc button • to create the HTML documentation • based on the Javadoc comments • This will generate HTML for all files in the same directory as all open files • Generates an index.html as a starting point Georgia Institute of Technology

  8. Javadoc Exercise • Add a class javadoc comment and method javadoc comments to the Student class • Execute Javadoc and check out the created documentation Georgia Institute of Technology

  9. Create a ClassPeriod • A teacher has students in each class period • Each period can have different students • For a class period we might want to know • The teacher’s name • The period number • The students in that period Georgia Institute of Technology

  10. UML Class Diagram • There is a standard way to diagram object-oriented classes • It is a UML class diagram • It shows the classes as boxes and the relationships between them Shows inheritance Has a or association Georgia Institute of Technology

  11. Creating a ClassPeriod class • We want fields for the • Teacher’s name • Period number • Students in the period • What type should each of these be? • A name can be a string • A period number can be an integer • The students in the period can be an array of Student objects • With a max of 35 students in a class period Georgia Institute of Technology

  12. Create a Class Exercise • Declare a new class ClassPeriod in the file ClassPeriod.java • Add the fields: • private String teacherName; • private int periodNumber; • private Student[] studentArray = new Student[35]; Georgia Institute of Technology

  13. Create a Class Exercise - Continued • Add constructors to ClassPeriod • Add the no argument constructor • Add a constructor that takes the teacher’s name and the period number • Remember that constructors are declared as public ClassName(paramList) { } Georgia Institute of Technology

  14. Add Accessors and Modifiers • Add methods to get and set the fields in the class period public String getTeacherName() { return this.teacherName; } public void setTeacherName(String theName) { this.teacherName = theName; } Georgia Institute of Technology

  15. Override toString • Add the following method to ClassPeriod public String toString() { } • Add code to the method to return a String with the teacher’s name, the period number, and the number of students in the class period • The length of the array isn’t a count of the actual students • Find out how many in the array are not null Georgia Institute of Technology

  16. Summary • Comments are added to make a program • Easier to read and understand • Comments are ignored by the compiler • There are three types of comments in Java • // end of line • /* multi line */ • /** java doc */ • Javadoc is a utility that comes with the jdk • Produces HTML documentation from Javadoc comments • UML is a standard way to diagram object-oriented designs • A class diagram shows classes and the relationships between them Georgia Institute of Technology

More Related