it is a java question, thank you very much!!
GeoCoordinate.java
//Program saved as GeoCoordinate.java
public class GeoCoordinate
{
//member variables
private double longitude;
private double latitude;
//default constructor
public GeoCoordinate()
{
latitude=0.0;
longitude=0.0;
}
//constructor with parameters
GeoCoordinate(double longitude,double latitude) throws
IllegalArgumentException
{
//check if values for latitude and
longitude are valid, if valid set the coordinates
if(longitude>-90.0 &&
latitude<90.0)
{
this.longitude=longitude;
this.latitude=latitude;
}
//if not valid throw
IllegalArgumentException
else
throw new
IllegalArgumentException("Wrong argument(s) upon construction of
GeoCoordinate");
}
//method that returns longitude
public double getLongitude()
{
return longitude;
}
//method that returns latitude
public double getLatitude()
{
return latitude;
}
//method that checks if two coordinates are
equal
public boolean equals(GeoCoordinate g)
{
//check if the latitude and
longitude of g is equal to current latitude and longitude
if(this.latitude == g.latitude
&& this.longitude == g.longitude)
{
return
true;
}
else
return
false;
}
//method that checks if two coordinates are within
bounds
boolean isWithinBounds(GeoCoordinate sw, GeoCoordinate
ne)
{
//check if the coordinates of sw
and ne are within the area of the current coordinates
if(this.latitude >= sw.latitude
&& this.latitude <= ne.latitude &&
this.longitude >= sw.longitude &&
this.longitude <= ne.longitude)
{
//return true if
within bounds
return
true;
}
else
return
false;
}
//override the toString method to print the
coordinates
@Override
public String toString() {
return "(" + this.longitude + "," +
this.latitude + ")";
}
}
GeoCoordinateTest.java
//Program saved as GeoCoordinateTest.java
public class GeoCoordinateTest {
public static void main(String[] args) {
//create objects for
GeoCoordinate
GeoCoordinate
currentLocation;
GeoCoordinate sw, ne;
//set the coordinates for
cuurentLocation
currentLocation = new
GeoCoordinate(20.0, 30.0);
//set coordinates foe sw
sw = new GeoCoordinate(10.0,
10.0);
//set coordinates for ne
ne = new GeoCoordinate(30.0,
30.0);
//print the current location
System.out.println(currentLocation);
//check if currentLocation is equal
to sw
System.out.println(currentLocation.equals(sw));
//check if sw and ne are within
bounds
System.out.println(currentLocation.isWithinBounds(sw, ne));
//try to create coordinates which
are not valid
try{
GeoCoordinate
wrongCoordinate = new GeoCoordinate(-100.0, 20.0);
}catch(IllegalArgumentException
e){
//print the
message if exception is caught
System.out.println("caught IllegalArgumentException:
"+e.getMessage());
}
}
}
Output:
it is a java question, thank you very much!! Question 2 20 marks) Write a class...
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...
write the following code in java thank you and if you can, could you please write the code in replit and sent me a link to it replit is basically like a online compiler and you can write java code on it thank you The first part is to implement one of the questions from your examination. /* A Range objects represents an integer range, such as 1-10 or 50701-50799. The lower and upper bounds of a Range are given...
U8ing separate files, write th definition for a clas called Poit and a class called Cirele 1. The class point has the data members (double) and y (double) for the x and y coordinates The class has the following ember functions a) void set x (double) to set the x data member b) void set y(double) to set the y data member c) double get-x() to return th the data member d) double get yO to zeturn the the y...
Using separate files, write the definition for a class called Point and a class called Circle. The class point has the data members x (double) and y (double) for the x and y coordinates. The class has the following member functions: a) void set_x(double) to set the x data member b) void set_y(double) to set the y data member c) double get_x() to return the the x data member d) double get_y() to return the the y data member e)...
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...
Write a simple class representing a Polygon up to 6 sides: the Polygon class has 5 fields: Regular, sides, sideLength, angle, apothem Polygon: Regular: boolean sides: int sideLength: double angle : double apothem : double Provide a no-arg constructor for this class initializes the object and sets the instance variables to: Regular: true sides: 3 sideLength: 1 angle : 60 apothem : SquareRoot(3)/2 Provide the following methods: Set number of sides set the length of the sides set the angle...
java problem
here is the combination class
class Combination
{
int first,second,third, fourth;
public Combination(int first, int second, int
third,int fourth)
{
this.first=first;
this.second=second;
this.third=third;
this.fourth=fourth;
}
public boolean equals(Combination other)
{
if ((this.first==other.first)
&& (this.second==other.second) &&
(this.third==other.third) &&
(this.fourth==other.fourth))
return
true;
else
return
false;
}
public String toString()
{
...
Requirements: Your Java class names must follow the names specified above. Note that they are case sensitive. See our template below. BankAccount: an abstract class. SavingAccount: a concrete class that extends BankAccount. o The constructor takes client's firstname, lastname and social security number. o The constructor should generate a random 6-digit number as the user account number. o The initial balance is 0 and the annual interest rate is fixed at 1.0% (0.01).o The withdraw method signature...
You will write a two-class Java program that implements the Game of 21. This is a fairly simple game where a player plays against a “dealer”. The player will receive two and optionally three numbers. Each number is randomly generated in the range 1 to 11 inclusive (in notation: [1,11]). The player’s score is the sum of these numbers. The dealer will receive two random numbers, also in [1,11]. The player wins if its score is greater than the dealer’s...
Write code in Java programming language. The ShoppingCart class will be composed with an array of Item objects. You do not need to implement the Item class for this question, only use it. Item has a getPrice() method that returns a float and a one-argument constructor that takes a float that specifies the price. The ShoppingCart class should have: Constructors: A no-argument and a single argument that takes an array of Items. Fields: • Items: an array of Item objects...