QuestionQuestion

Write a program that will serve as a simulation of an autopilot system for an autonomous ship. An input file containing the latitude and longitude of waypoints (places the ship must sail to under computer control) will be provided. Your program will read this file and simulate the ship sailing. This will entail keeping track of where the ship is currently, what direction it is sailing, and adjusting the direction the ship sails to bring it to the next waypoint in the list. You will need to have at least two external class files: one for the ship object, and one for the waypoint object. You may read the waypoint file one waypoint at a time, or you can read in the whole file into an ArrayList if you prefer. Your program must send output containing the ship position, direction, and speed to a file. This file can then be used for later analysis, such as visualization. The program should terminate when all the waypoints have been reached, or after a certain maximum number of seconds has elapsed.

The file consists of waypoints, first the latitude (decimal degrees north), then longitude (decimal degrees west).

Please assume the following parameters for your ship: it will travel at a steady speed of 15 miles per hour, and can turn at a maximum rate of one degree per second (60 degrees per minute).

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Project2 {

    public static void main(String[] args) {
       ArrayList<WayPoint> wps = readFile("autopilot_waypoints.txt");
       Ship ship = new Ship(wps.get(0));

       /**
         * Your program must send output containing the ship position,
         * direction, and speed to a file. This file can then be used for later
         * analysis, such as visualization. The program should terminate when
         * all the waypoints have been reached, or after a certain maximum
         * number of seconds has elapsed
         */
       Scanner keyboard = new Scanner(System.in);
       System.out.print("Enter number of second ");
       long seconds = keyboard.nextInt();
       seconds *= 1000000000;
       boolean timeOut = false;
       long start = System.nanoTime();

       try {
            FileWriter fw = new FileWriter("output.txt");
            for (int i = 1; i < wps.size(); i++) {

                // get next point
                WayPoint next = wps.get(i);

                // turn the ship
                ship.turn(next, fw);

                //move the ship
                ship.move(next, fw);

                // calculation of floating numbers has difference
                // between the expected value and the result
                // so we have to set it manually
                ship.setWp(next);
                //System.out.println(ship.toString());
                fw.write(ship.toString() + System.lineSeparator());
                //System.out.println("");
                if (System.nanoTime() - start > seconds) {
                   System.out.printf("Program terminates after %d seconds\n",
                            seconds / 1000000000);
                   timeOut = true;
                   break;
                }
            }...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$73.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats