tags:

views:

43

answers:

1

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 Earthquakes

 // 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

A: 
foreach earthquake as e
   e.determineClassification(this)
   e.printdata(this)

function determineClassification(e)
   e.class = class1

function printdata(e)
   e.print()
Orbit
hmm still a bit confused. my determine classification () is set up like that, and inside it they have if then else statements (on magnitude and classification). So is it referring to determineclassification(earthquake), set determineclassification, or call a print method for determineclassification.
james
i think all it is saying is that you need to call the determineClassification method on the earthquake object before you print it, although usually 'accessor' methods get information about an object(something like getPrintData()).
Orbit
I understand printing it, but still not sure what to do with the determine method, determineclassification (earthquake1, 2, 3, 4) printdata void eq(Earthquake1). I am sorry if I am making it more complicating, but really I am only stuck in this one particular area.
james
updated question above.
james
are you looking for help with the logic inside determineClassification? It may help if you post your code.
Orbit
alright updated my question again, hope it clears things up from my end.
james
ok, in your main function at the end, you need to call dertermineClassification right before you print.
Orbit
so would that go right after all the earthquake methods and before the print method and if so what do I put in the class method. Would it be determineclassification (earthquake1, earthquake2, earthquake3, earthquake4) and then below it earthquake1 to set up a call.
james
yes. and in the method you either return the classification or set the classification for each earthquake.
Orbit
so it would be one of two ways determineclassification (methods inside) return, OR same thing except earthquake1 (lat, lon, mag) and vice versa underneath the determineclassification () am I correct.
james