Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Answer ALL questions
- You are advised to read the Appendix before attempting any of these questions.
- You are provided with a BlueJ project in the folder c:\exam\cities. You MUST use
- this project for all of your answer. Note that BlueJ automatically saves your work so
- you do not need to use “save” or “save as” to save any of your answers. Work saved
- outside of c:\exam\cities may not be collected.
- 1. The first task is to edit the Java class called Location. Be careful not to change
- the method that has already been written in this class, write your code above that
- method. Give the class:
- a) TWO instance variables. One holds the latitude (type double) and the other
- holds the longitude (type double); (1 mark)
- b) A constructor with two parameters, the latitude and the longitude. The body of
- the constructor should initialise the values of the two instance variables from
- the values of the parameters. Note also that long is a reserved word in Java
- and so cannot be used as the name of a variable. (2 marks)
- c) An accessor method to return the latitude AND an accessor method to return
- the longitude. (2 marks)
- d) Write a method to test equality of a location object against another location
- object. Your method should be called equals and it will have ONE parameter
- of type Location. This method will return true if this location has the same
- latitude and longitude as the location passed as the parameter value.
- Otherwise it will return false.
- (6 marks)
- After completing the above, you should manually construct an object from your
- Location class in BlueJ and call each of the methods to ensure it works. Use the
- object inspector to ensure that the instance variables have been assigned
- properly. Construct more Location objects as necessary to test your equals
- method correctly returns true or false as described.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement