Creating Classes part 4 - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

Creating Classes part 4

Description:

comment ends at the end of this line /* comment ends with next ... Execute Javadoc and check out the created documentation. Georgia Institute of Technology ... – PowerPoint PPT presentation

Number of Views:24
Avg rating:3.0/5.0
Slides: 17
Provided by: barbar225
Category:
Tags: check | classes | creating | georgia | line | out | part | tech

less

Transcript and Presenter's Notes

Title: Creating Classes part 4


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

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

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

4
Javadoc Comments
  • Add a comment before the class definition
  • That explains the purpose of this class
  • And says who wrote it
  • _at_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.
  • _at_author Barb Ericson
  • /
  • public class Student

5
Method Comments
  • Add a comment before each method
  • What the parameters are
  • _at_param name info
  • What is returned
  • _at_return info
  • /
  • Method to set the name for this student
  • _at_param theName the new name to use
  • _at_return true if success else false
  • /
  • public boolean setName(String theName)

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

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

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

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 teachers name
  • The period number
  • The students in that period

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
11
Creating a ClassPeriod class
  • We want fields for the
  • Teachers 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

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 Student35

13
Create a Class Exercise - Continued
  • Add constructors to ClassPeriod
  • Add the no argument constructor
  • Add a constructor that takes the teachers name
    and the period number
  • Remember that constructors are declared as
  • public ClassName(paramList)

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

15
Override toString
  • Add the following method to ClassPeriod
  • public String toString()
  • Add code to the method to return a String with
    the teachers name, the period number, and the
    number of students in the class period
  • The length of the array isnt a count of the
    actual students
  • Find out how many in the array are not null

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
Write a Comment
User Comments (0)
About PowerShow.com