Weekly Plans and Assignments: 4. Thursday(12/03): Review of Java Classes and Methods. Writing the FindMaxValue class. Prog7_01 Maximum Value of a Function in a Given Interval. Here is the code that uses the FindMaxValue class. HW: Finish Prog7_01 from class and turn-in tomorrow. 5. Friday(12/04): Prog7_02 Analysis of the Path of a Projectile. HW: Finish Prog7_02 from class and turn-in tomorrow. 6. Monday(12/07): Writing Classes for Statistical Applications. The MeanFinder, Median Finder, and ModeFinder classes. Prog7_03 Finding the Mean, Median, and Mode. HW: Finish Prog7_03 from class and turn-in tomorrow. 7. Tuesday(12/08): Writing the Variance class. Prog7_04 Finding the Variance and Standard Deviation from a data set. HW: Finish Prog7_04 from class and turn-in tomorrow. 8. Wednesday(12/09): Writing the Permutation and Combination classes. Prog7_05 Permutations and Combinations. HW: Finish Prog7_05 from class and turn-in tomorrow. 9. Thursday(12/10): Writing the Poisson Probability class. Prog7_06 Calculating Poisson Probabilities. HW: Finish Prog7_06 from class and turn-in tomorrow. 10. Friday(12/11): Writing the Hypergeometric Random Variable class. Prog7_07 The Hypergeometric Random Variable. HW: Finish Prog7_07 from class and turn-in Monday. 4. MONDAY(12/14): Review I for Semester Exam. All assigned Homework Programs due, NO Exceptions. HW: Complete Review Handout. Semester Folder check (50 pts.) due, NO Exceptions, during your Semester Exam. 5. TUESDAY(12/15): Period 1 Semester Exam. Shortened classes for Periods 2-7. Review II for Semester Exam. HW: Study for Semester Exams. 6. WEDNESDAY(12/16): Late Start (10:30). Period 2 & 3 Semester Exams. HW: Study for Semester Exams. 7. THURSDAY(12/17): Late Start (10:30). Period 4 & 5 Semester Exams. HW: Study for Semester Exams. 8. FRIDAY(12/18): Late Start (10:30). Period 6 & 7 Semester Exams. HW: Have a Safe and Happy Holiday Break!
Very Important: If you have any questions or were absent from class, see me before school (8:00 - 8:30 AM), during Lunch, or after school. Best to send an email to rpersin@fau.edu.
Website Notes - Ch.7: Java
Classes and Methods. Java utilizes the basic object technology
found in C++. In a nutshell, the Java language supports the idea of data packaging, or encapsulation, through its mechanism. A Java class is an association between data elements and/or functions, much like an extended struct in C (or a C++ class). In fact, there are no structs in Java at all; the mechanism of grouping together similar elements is achieved only by creating a class. The functional members of a class are referred to as the class methods.
Just as a C struct may contain other structs within it, a Java class may be
built on top of another class--although only one at a time--and inherit that class's behaviors as well. Java has its own syntax for describing methods and classes. It supports public class members, which are visible outside the class;
protected members, which are visible only within the class and its subclasses; and private members, which are only visible within that
particular class. Java supports abstract (virtual) classes, in which some or
all of the member functions are declared, but not defined--they have no function body, so that
only subclasses which fully define those functions may be used. If you have some experience with C++ programming, many of these concepts will be familiar to you. However, there are several striking differences
between C++ and Java. Much of the implicit behavior that C++ takes for granted is absent in Java.
For example, there are no default constructors: a Java program must
explicitly call the operator new to create a new instance of a class. In addition, arithmetic operators such as "+" or "= =" may not overload in
Java. There is no way for the programmer to extend the behavior of "+" beyond what Java provides intrinsically. Another highly visible departure from C and C++
is that there are no pointers (and logically, no pointer arithmetic) in Java.
Here is an example of a class called Sphere: class Sphere {
Which is accessed by the program CreateSpheres: public class CreateSpheres Types of methods. There are two types of methods. (1) Instance methods are associated with an object and use the instance variables of that object. This is the default. (2) Static methods use no instance variables of any object of the class they are defined in. If you define a method to be static, you will be given a rude message by the compiler if you try to access any instance variables. You can access static variables, but except for constants, this is unusual. Static methods typically take all they data from parameters and compute something from those parameters, with no reference to variables. This is typical of methods which do some kind of generic calculation. A good example of this are the many utility methods in the predefined (See Math and java.util.Random). Below is the program that finds the maximum value of a function in an interval. public class MaxFinder { From outside the defining class, an instance method is called by prefixing it with an object, which is then passed as an implicit parameter to the instance method, A static method is called by prefixing it with a class name,
Curiously, it can also be qualified with an object, which will be ignored, but the class of the object will be used. ExampleHere is a typical static method. class MyUtils {
. . .
//================================================= mean
public static double mean(int[] p) {
int sum = 0; // sum of all the elements
for (int i=0; i<p.length; i++) {
sum += p[i];
}
return ((double)sum) / p.length;
}//endmethod mean
. . .
}
The only data this method uses or changes is from parameters (or local variables of course). Why declare a method
|
|
|
CH.1_Introduction to Computer Science CH.3_Char, Loop, Selection Statements |
|
|
|