1) Write a program in Java that has 2 attributes (type double) latitude and longitude, initialize the longitude of GeoPoint object
with a constructor and set it up to 90;
2) Write 2 getters and 2 setters for each attribute of the GeoPoint.
– The getters are methods to query the state of the attribute (the method should return a value)
– The setters are methods to modify the state of the attribute (the method should be called with a parameter (value))
3) Write a distanceFrom() method that also return a value which is the distance between the initiated longitude of the first
GeoPoint object and the longitude of a second GeoPoint object
PS: For the second GeoPoint object, you must create it using the constructor as a second object in the Main method and
assign it a random longitude value using the setter of the longitude.
Create public static void main method and code instructions to do the following:
– Call 2 GeoPoint objects (point1 and point2) by using constructor.
– Print a message on the console asking for the longitude of the GeoPoint object point2.
– Read the value using java.util.Scanner library and assign to the longitude of point2 using the setter of the longitude.
– Print a message on the console that informs you about the value of the longitude of point1.
– Declare distance a new double variable and assign to it the distanceFrom() method.
– Print on the console a message stating is the distance between the longitude of point1 and the longitude of point2
is: the value of the declared variable distance
—————————————————————-
Examples using Time as an object, hour and minutes as attributes:
To call/invoke new objects:
Time t1 = new Time ();
Time t2 = new Time ();
… as many objects as you wish.
Getter:
public int gethour () {
return hour;}
Setter:
public void setminutes (int min) {
minutes=min;}
To call/invoke this setter: t1.setminutes(33);
Example to read from the console into a parameter:
Scanner inputforname = new Scanner(System.in);
System.out.println(“What is your name?”);
String UsersName= inputforname.nextLine();
System.out.println(“Hello, “+UsersName+” Nice to meet you”)
—————————————————————
Starting Code
—————————————————————-
import java.util.Scanner;
public class GeoPoint {
private double latitude;
private double longitude;
/*Getter and Setter for latitude*/
public double getlat() {return latitude;}
public double setlat(double lat) {return this.latitude = lat;}
/*Exercise1: add a getter and setter for longitude here*/
/*A constructor for the Class*/
public GeoPoint() {
this.latitude = 45;
this.longitude = 45;
}
/*
* Exercise2: Write a constructor which assign user input to the longitude and latitude
*/
public double distanceFrom(GeoPoint geo){
double distance;
/*Exercise3: Calculate the distance between two longitudes*/
return distance;
}
public static void main(String[] args) {
/*Exercise4: Define 2 pairs of lat and long here with different values*/
/*Exercise5: Create point1 and point2*/
/*Exercise6: Prompt new longitude for one of the points and set the new longitude,
*then print the new point’s longitude */
/*Exercise7: Print out the distance between two point’s longitude*/
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more