Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Discovering Advanced Algebra An Investigative Approach

Authors: Jerald Murdock, Ellen Kamischke, Eric Kamischke

1st edition

1559539844, 978-1604400069, 1604400064, 978-1559539845

More Books

Students also viewed these Programming questions

Question

What is the fundamental question that sensitivity analysis answers?

Answered: 1 week ago