Question
How can I change this code so that when the latitude and longitude is changed each time the code will write the latitude and longitude
How can I change this code so that when the latitude and longitude is changed each time the code will write the latitude and longitude to a file.
package gpsltlg;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class GPSltlg {
// parameterized constructor
public GPSltlg(double lt, double lg) throws FileNotFoundException {
Address address = new Address();
Location location = new Location(lt, lg);
}
public static void main(String[] args) throws FileNotFoundException {
Scanner usrin = new Scanner(System.in);
double lat, lon;
System.out.print("Enter the latitude: ");
lat = usrin.nextDouble();
System.out.print("Enter the longitude: ");
lon = usrin.nextDouble();
usrin.nextLine(); // read and discard left by nextDouble
GPSltlg gps = new GPSltlg(lat, lon);
}
}
class Address {
private String numberAndStreet;
private String city;
private String state;
private String zipcode;
// default constructor
public Address() throws FileNotFoundException {
Scanner usrin = new Scanner(System.in);
System.out.print("Enter the number and street: ");
numberAndStreet = usrin.nextLine();
System.out.print("Enter the city: ");
city = usrin.nextLine();
System.out.print("Enter the state: ");
state = usrin.nextLine()
System.out.print("Enter the zipcode: ");
zipcode = usrin.nextLine();
System.out.println(numberAndStreet);
System.out.println("Location : " + city + ", " + state + ", " + zipcode);
}
}
class Location {
double lt, lg;
// parameterized constructor
public Location(double lt, double lg) {
this.lt = lt;
this.lg = lg;
System.out.println("@" + lt + "." + lg);
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
To modify the code so that it writes the latitude and longitude to a file each time they are changed you can make the following changes Add a file output stream and a print writer to the GPSltlg class ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started