Clarification of a specific method
On my homework I have a question/part where I am confused at (can't understand it).
Iv ) The main method calls the printdata() method for each Earthquake object. The printData() method accepts an Earthquake object as a parameter and prints all the Earthquake's idea, including latitude, longitude, magnitude and classification. Remember that you will need to call the determineClassification() method for the Earthquake object before calling the accessor method and printing the classification.
I understood everything up till the bolded era, what does it mean when it says call the determine method for earthquake object before calling accessor method and printing it.
Part I: earthquake service class has 4 attributes, lat, lon, mag, classification
include following for part I, constructor, second constructor with parameter (lat, lon, mag), accessor for method for each attribute, mutator method for all attributes EXCEPT for classification.
A method named determineclassification() that uses range checking, based on the table shown above and the value of the magnitude attribute, and sets the value of the classification attribute to the appropriate word specified in the table. Remember to choose either low end or high end range checking when designing this method.
Part II italicized.
PSEUDO CODE.
Earthquake service class
public class Earthqu开发者_开发问答akes
// declarations
private num latitude
private num longitude
private num magnitude
private String classification
public Earthquakes ( )
latitude = 0.0
longitude = 0.0
magnitude = 0.0
classification = “new”
return
public void Earthquake(num lat, num lon, num mag)
latitude = lat
longitude = lon
major = maj
return
public num getLatitude( )
return latitude
public num getLongitude ( )
return longitude
public String getMagnitude( )
return magnitude
public num getClassification( )
return classification
public void setLatitude (num lat)
latitude = lat
return
public void setLongitude (num lon)
longitude = lon
return
public void setMagnitude(num mag)
magnitude = mag
return
Public determination class ()
If magnitude > 0 AND magnitude < 2.9 then
Classification = Micro
Else if magnitude > 3 AND magnitude < 3.9 then
Classification = Minor
Else if magnitude 4 > AND magnitude < 4.9 then
Classification = Light
Else if magnitude 5 > AND magnitude < 5.9 then
Classification = Moderate
Elseif magnitude 6 > AND magnitude < 6.9 then
Classification = Strong
Else if magnitude 7 > AND magnitude < 7.9 then
Classification = Major
Else if magnitude >= 8
Clarification = Great
end if
end class
HazardsProgram class
Public class HazardsProgram
Public void main ()
// Declarations
Earthquake1 (lat 47.74N, lon 154.34E, mag 5.1)
Earthquake2 (lat 35.44N, lon 97.46W, mag 2.8)
Earthquake3 (lat 29.73S, lon 177.98W, mag 6.5)
Earthquake4 (lat 61.04N, long 147.73W, mag 9.2)
Print Data void eq(earthquake1)
Output latitude, longitude, magnitude, classification
Return
End class
foreach earthquake as e
e.determineClassification(this)
e.printdata(this)
function determineClassification(e)
e.class = class1
function printdata(e)
e.print()
精彩评论