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

1 Expert Approved Answer
Step: 1 Unlock

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 ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!