Question

Language: Java For this file, it should be concrete. I don't know how to write a...

Language: Java

For this file, it should be concrete. I don't know how to write a code with the following private field & associated getter methods:

  • final String NAME - a constant that represents the name of a location

  • final double LATITUDE - a constant that represents the latitude (x) of that location

  • final double LONGITUDE - a constant double represents the longitude (y) of that location

Then, create a following constructor to initialize Location(String name, double lat, double long)

After, write the following methods:

1. public boolean equals(Object other). This returns a boolean representing whether another object is logically equivalent to this instance of Location. For two Location instances to be equivalent, their latitude and longitude must be equal. Their name’s do NOT have to be the same. Implement this method as you have been taught in the module.

2. public String toString(). This returns the String representation of this Loca- tion object’s stored information in the following format: “(name) @ ((latitude), (longitude))”. For example, a possible output of the toString() method could look like this: “CoC @ (15.32, 35.32)”

3. Getters for all fields.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
class Location {

        final String NAME;
        final double LATITUDE;
        final double LONGITUDE;

        public Location(String nAME, double lATITUDE, double lONGITUDE) {
                NAME = nAME;
                LATITUDE = lATITUDE;
                LONGITUDE = lONGITUDE;
        }

        public String getNAME() {
                return NAME;
        }

        public double getLATITUDE() {
                return LATITUDE;
        }

        public double getLONGITUDE() {
                return LONGITUDE;
        }

        @Override
        public boolean equals(Object obj) {
                if (this == obj)
                        return true;
                if (obj == null)
                        return false;
                if (getClass() != obj.getClass())
                        return false;
                Location other = (Location) obj;

                return (LATITUDE == other.LATITUDE) && (LONGITUDE == other.LONGITUDE);
        }

        public String toString() {
                return NAME + " @ (" + LATITUDE + ", " + LONGITUDE + ")";
        }
}
Add a comment
Know the answer?
Add Answer to:
Language: Java For this file, it should be concrete. I don't know how to write a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need this in c++ please Write a Map class that is composed of a Location...

    I need this in c++ please Write a Map class that is composed of a Location class. Location class has three private variable string nameOfCity, double variables, latitude and longitude. It has a constructor to initialize these and also the usual getters. It has three functions: string toString() which prints :double getFlyingTime(Location l) which returns the flying time between this and location l. It uses the formula that time = distance/speed. speed = 673 miles/hour. No need to convert to...

  • JAVA City Files Program: Deserialize objects from a file. Print the data contained in the fields...

    JAVA City Files Program: Deserialize objects from a file. Print the data contained in the fields of the objects to a plaintext file. The Cities.dat binary file contains TEN serialized City objects. Each City object has name, population, latitude, and longitude fields. Prior to being serialized into the file, all ten objects had their fields set. City Java: public class City implements Serializable { private String name; private int population; private double latitude; private double longitude; public City(String n, int...

  • it is a java question, thank you very much!! Question 2 20 marks) Write a class...

    it is a java question, thank you very much!! Question 2 20 marks) Write a class named GeoCoordinate that retains the longitude and latitude of an object on earth. Both longi- tude and latitude are represented as double values that must be in the range [-90.0, 90.00. The class has the following constructors: GeoCoordinate0, which initializes the latitude to 0.0 (the equator, the longitude to 0.0 (the prime meridian) GeoCoordinate(double longitude, double latitude): initializes the longitude and latitudes to values...

  • This is a java file and I am very confused on how to do this project!...

    This is a java file and I am very confused on how to do this project! please help!! Specifications Overview: You will write a program this week that is composed of three classes: the first class defines Ellipsoid objects, the second class defines EllipsoidList objects, and the third, Ellipsoid ListApp, reads in a file name entered by the user then reads the list name and Ellipsoid data from the file, creates Ellipsoid objects and stores them in an ArrayList of...

  • The following C++  code contains an incomplete program that should be able to calculate the distance between...

    The following C++  code contains an incomplete program that should be able to calculate the distance between a series of geocoded locations. Two parts of the program need to be completed: 1. The portion of the main() function that calculates the distances between each of the hard-coded 5 locations, and stores it in a two-dimensional array declared as distances. 2. A portion of the calculateDistanceBetweenLocations(l1, l2) function; omitted code spaces are designed with a // TODO: comment. The code is properly...

  • The following is for java programming. the classes money date and array list are so I are are pre...

    The following is for java programming. the classes money date and array list are so I are are pre made to help with the coding so you can resuse them where applicable Question 3. (10 marks) Here are three incomplete Java classes that model students, staff, and faculty members at a university class Student [ private String lastName; private String firstName; private Address address; private String degreeProgram; private IDNumber studentNumber; // Constructors and methods omitted. class Staff private String lastName;...

  • Please help me with this code. Thank you Implement the following Java class: Vehicle Class should...

    Please help me with this code. Thank you Implement the following Java class: Vehicle Class should contain next instance variables: Integer numberOfWheels; Double engineCapacity; Boolean isElectric, String manufacturer; Array of integers productionYears; Supply your class with: Default constructor (which sets all variables to their respective default values) Constructor which accepts all the variables All the appropriate getters and setters (you may skip comments for this methods. Also, make sure that for engineCapacity setter method you check first if the vehicle...

  • Please help me do the java project For this project you will be reading in a...

    Please help me do the java project For this project you will be reading in a text file and evaluating it in order to create a new file that represents the Class that will represent the properties of the text file. For example, consider the following text file: students.txt ID              Name                              Age                    IsMale           GPA 1                Tom Ryan                       22                       True              3.1 2                Jack Peterson                31                       True              2.7 3                Cindy LuWho                12                       False             3.9 When you read in the header line, you...

  • using CSCI300 java Given the following UML Class Diagram Club_Card # card_num : String # name...

    using CSCI300 java Given the following UML Class Diagram Club_Card # card_num : String # name : String # age: int # year: int + Club_Card (all parameters) + Setters & Getters + toString() : String + equals(x: Object): boolean [10 pts] Define the class Club_Card, which contains: 1. All arguments constructor which accepts all required arguments from the main and instantiate a Club_Card object. 2. Set & get method for each data attribute. 3. A toString() method which returns...

  • please write program in java and comment the code clearly. I am providing previous classes Media...

    please write program in java and comment the code clearly. I am providing previous classes Media and payment codes to be used for this class.(its not a big code to write , it seems ,because i added previous classes , pleases help. public class Media { String name; int year;    // a constructor which initializes the media with the provided name and publication year. public Media(String name, int year) { this.name = name; this.year = year; }    //...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT