Computer Science ( A ) - Exercises 07.01-05
Compare the paint methods of Module09.java and Module10.java. In program Module10.java, why are all of the method calls preceded with "House."?
They are proceeded with house in Module10 because all of the methods are no longer in the same class as *public*, so the class must be identified when calling on the methods.
If you are calling a class method, when is using the class identifier optional?
Using the class identifier is *optional* if you are calling a method that is in the *same* class. *Use of the class identifier is optional if a method is called from a program statement in another method, which resides in the same class as the method being called.*
If you are calling a class method, when is using the class identifier required?
Using the class identifier is *required* if you are calling a method that is in a *different* class. *Use of the class identfier is required if a method is called in a program statement that resides outside the class of the method being called.*
What kind of values do void methods return?
Void methods *do not return any values*, that is why they are called void methods... because their return date type is void. Void methods frequently *alter object data*, like the statement: tom.checkingDeposite(1000.0); which adds $1000.00 to the checking account balance of the tom object.
If both the method you are calling, and the method you are calling from - usually the main method - are in the same class, you _________________________________________________________________.
do not need to use the name of the class
Output to the monitor requires the use of a _____________________ object.
graphics
Another terrific benefit is that methods have a name or _______________.
identifier
List 4 simple data types.
int, double, char, boolean
Up to this point, every program you have worked with has had exactly one method. If it was an *application*, it was the ____________ method. If it was an applet, it was the ___________ method.
main, paint
Make sure that you do not add a semi-colon at the end of the ___________________________.
method heading -------------------------------------------------------------- Yes, you are told that every program statement ends with a semi-colon, but *a method heading, class heading or loop heading is not a program statement* and thus does not get a semi-colon.
Objects contain data and what else?
methods
Common methods should be placed in a ____________________.
module ( *One task, one module* )
What do *simple/primitive data types* store?
only a single value
What Applet method controls the graphics display of an Applet in the same manner that the main method controls the sequence in an application program?
paint method
Programs should NOT be written by . . .
placing all of the program statements in the *main* or *paint* methods.
It is not possible to create large, reliable programs without being very conscious of ________________.
program design
What word do you NOT use when declaring a 2nd or 3rd class in a program?
public
If a file has more than one class, only the class with the ________________________________ is declared *public*.
same name as the file
When calling a method you, . . .
state the identifier (name of the class), followed by a period, followed by the method identifier (name of the method). This formula is called the *class-dot-method format*. -------------------------------------------------------------- Exs: Math.sqrt Module03.fullname(), Module03.street(), and Module03.cityStateZip().
What are the methods called that are incomplete, but do have a heading and a set of braces?
stubs
Methods are also called...
subroutines
A class is considered a _____________ and methods are considered ____________.
toolkit, tools
If you place a class in its own file, then . . .
you can state it as *public*
If you are in the main method, and you want to call a hiss method from a Boo class, what would be the exact syntax?
*Boo*.*hiss*();
List the 3 trigonometric methods of the Math class.
*Math.sin(p), Math.cos(p), Math.tan(p)*, Math.asin(p), Math.acos(p), Math.atan(p)
The *main* method is a . . .
*primary* method
A user-defined method requires . . .
- A heading, which includes the method name - A set of { } braces to contain the method body statements - A body of program statements inside the { } braces
__________________________________ continues by placing modules of a common nature into a separate class.
- Object Oriented Design
Programs statements that perform a specific purpose should _______________________________________. These things should be called _______________________.
- be placed inside their own modules - methods
In the statement Bank tom; Bank is the _________________ and tom is the _________________.
- data type - variable
In the statement int num; int is the _________________ and num is the _________________.
- data type - variable
In order to call an object method, a _____________________________________________ and _______________________________________________________.
- object *must* be created - you need to use the name of the object in order to call the method
What are the 2 categories of methods?
1) *return methods* e.g. public int number() System.out.println(tom.getChecking()); -------------------------------------------------------------- 2) *void methods* e.g. public static void number() tom.checkingDeposit(1000.0);
A method can be . . .
1. A method can be *BOTH a void method and a class method*. 2. A method can be *BOTH a void method and an object method*. 3. A method can be *BOTH a return method and a class method*. 4. A method can be *BOTH a return method and an object method*. -------------------------------------------------------------- So there are *void class methods, void object methods, return class methods, and return object methods*.
How do you create a large graphics program?
1. create the <paint> method 2. create *stubs* 3. write the first method and make sure it works 4. write the next method and make sure it works 5. repeat step 4 until the entire program is done
Class methods are normally what?
Class methods are normally utility methods that do not access changing data fields.
What is the next step in writing your graphics program?
Complete one method at a time and test that method before continuing to the next method.
In the paint method of program Module15.java three different classes appear. Why are methods called from three different classes to draw a house?
In this program there is also a background displayed with the *Background* class and a tree is displayed with the Tree class.
Refer to the previous question. Why are these methods created incomplete?
It allows the program to compile before every method is completed.
What 2 things do class data types store?
It can store multiple pieces of information (class attributes) as well as several methods (class actions). Essentially *can store many values as well as methods*.
Refer to the previous question. Why was this not necessary in program Module09.java?
It was not necessary to identify the class with each method call because all of the methods were in the same class.
How must the methods of the Math class be accessed?
Methods of the Math class are class methods and must be accessed using the *Math class identifier*. -------------------------------------------------------------- Ex: If you want to access the value of PI, you need to use *Math.PI* in your program. If you want to compute the square root of 100, you need *Math.sqrt(100)* in your program.
The process of placing statements that achieve a common purpose into its own module is . . .
Modular programming
What are the only two data fields of the Math class?
PI and E ( which do not change )
If you select to divide the graphics output into multiple modules you need to make sure that you do what?
Pass the graphics object to the other modules. e.g. public void paint(Graphics g) { drawFloors(g); } public static void drawFloors(Graphics g) { g.setColor(Color.blue); }
Why does Java make users create files that have the same name as the class?
So the Java compiler can find the class, if it is addressed in another program.
What is a good start for a graphics program?
Start with the paint method and enter the method calls for the different parts of the program.
Why does program Modlule05.java not compile?
The program will no longer compile because the methods are no longer contained in the same class.