Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please see my code that I have so far for a GPS program that I am working on. I

ID: 3561737 • Letter: P

Question

Please see my code that I have so far for a GPS program that I am working on. I need to have this completed by thursday this week--and I am a little stuck as to how to print out the required GPS coordinates for Salt Lake City (please see the full assignment below for help or instructions to what I need):

There are 3 classes (GpsApp (main method), Gps, and GpsCoordinates).

public class GpsApp {

public static void main(String[] args, String name)

{

GpsCoordinates gpsc = new GpsCoordinates(26.7, 32.5);

Gps gp = new Gps("place", gpsc);

gp.updatePosition(gpsc);

System.out.println(gp);

}

}

________

public class GpsCoordinates

{

private double lat;

private double lon;

public GpsCoordinates(double lat, double lon)

{

setLat(lat);

setLon(lon);

}

public double getLat()

{

return lat;

}

public void setLat(double lat)

{

this.lat = lat;

}

public double getLon()

{

return lon;

}

public void setLon(double lon)

{

this.lon = lon;

}

?

@Override

public String toString()

{

return lat + " " + lon;

}

?

?

}

_________

public Gps(String n, GpsCoordinates pos)

{

this.name = n;

this.position = pos;

}

public GpsCoordinates updatePosition(GpsCoordinates position)

{

position.setLat(position.getLat() + (Math.random()*5)-2.5);

position.setLon(position.getLon() + (Math.random()*5) -2.5);

return position;

}

public GpsCoordinates getPosition()

{

return position;

}

?

@Override

public String toString()

{

return name + ": " + position;

?

}

?

}

Gps Coordinates Class: Do not add or remove any public methods or constructors (NO print statements)

Gps Class: Do not add or remove any public methods or constructors (No print statements);

GpsApp (main method): See how the output should be (random)

Explanation / Answer

public class GpsApp {

    public static void main(String[] args)
    {
        GpsCoordinates gpsc = new GpsCoordinates(26.7, 32.5);
        Gps gp = new Gps("salt lake", gpsc);
        gp.updatePosition(gpsc);
        System.out.println(gp.toString());
    }

    public static class GpsCoordinates
    {
        private double lat;
        private double lon;

        public GpsCoordinates(double lat, double lon)
        {
            setLat(lat);
            setLon(lon);
        }

        public double getLat()
        {
            return lat;
        }
        public void setLat(double lat)
        {
            this.lat = lat;
        }
        public double getLon()
        {
            return lon;
        }
        public void setLon(double lon)
        {
            this.lon = lon;
        }
        @Override
        public String toString()
        {
            return lat + " " + lon;
        }
    }

    public static class Gps
    {
        String name;
        GpsCoordinates position;
        public Gps(String n, GpsCoordinates pos)
        {
            this.name = n;
            this.position = pos;
        }

        public GpsCoordinates updatePosition(GpsCoordinates position)
        {
            position.setLat(position.getLat() + (Math.random()*5)-2.5);
            position.setLon(position.getLon() + (Math.random()*5) -2.5);
            return position;
        }

        public GpsCoordinates getPosition()
        {
            return position;
        }

        @Override
        public String toString()
        {
            return name + ": " + position;
        }
    }
}

OUTPUT:

salt lake: 27.790025367090866 30.507026693279748

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote