



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Announcements Read 5.10 to 5.12. Javadoc Let's look at the Java API documentation again. Where does this all come from? Look at the Dice programming assignment โ where did the documentation for my class come from? Java provides a tool for generating this documentation right from your source code. The tool is called javadoc, and you can access it directly from BlueJ. javadoc generates documentation from the source code. Let's look at what it generates for our tech-support project [Tool menu โ project documentation]. Seems to be missing some information
public vs. private The key words public and private are access modifiers. Access modifiers define the visibility of fields, constructors, and methods. A public method or field can be accessed from within the same class, or from another class. A private method or field can be accessed from within the same class only. We just saw that there are two views of a class: the implementation view and the interface view. The interface is the set of details that someone using the class needs to see โ it provides information about how to use the class. Sometimes this is referred to as the public part of the class. The implemenation view shows us exactly how the class works. This view includes the method bodies and the field declarations. The user of a class does not need to know about the implementation (abstraction again!) So, the public keyword declares a field or a method to be part of the interface. The private keyword declares it to be part of the implementation. There are good reasons for preventing a user of a class from knowing about the class's implementation โ this principle is called information hiding.
while ( input <= 0 ) { S.O.PL("The number must be greater than 0"); S.O.PL("Please enter the number of times to roll the dice" ); input = stdin.nextInt(); } This is called a user input validation loop. This form is very typical: Get input while ( input is invalid ) print error message get input
Lab Create a new project. Make a new class named Roots. This class should have one public method: public void printRoots() This method should: