Advertisement
Guest User

xd

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