Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CSE 115 Intro to Computer Science I PLEASE USE JAVA Lab Exercise 06.1 ATC Utility Your textbook lists a class named FindNearestPoints on page 296

CSE 115 Intro to Computer Science I

PLEASE USE JAVA

Lab Exercise 06.1

ATC Utility

Your textbook lists a class named FindNearestPoints on page 296 the purpose of which is to find the two points closest to each other in a 2-dimensional space. For example, a map of a country will have a number of cities, each represented by an X-coordinate and a Y-coordinate and the program will find the two cities which are closest to each other.

The purpose of this exercise is to generalize this algorithm to finding the closest two points in a 3-dimensional space. For example, an air traffic controller has responsibility for a number of aircraft and each aircraft is represented by an X-coord, a Y-coord and a Z-coord.

This exercise will deal with a 3-dimensional array of coordinates, representing aircraft and will, for each aircraft in the list, find its 3 nearest neighboring aircraft. The result will be a list of 12 aircraft, each followed by the distances to each of its 3 nearest neighbors.

The fundamental declaration of the array will reflect the fact that the area around an airport is divided into geographically-based sectors in order to keep the number of aircraft assigned to any one controller to a minimum. So each aircraft will have 3 levels of identifying values, a sector number from 0 to 4, an aircraft ID number from 0 to 11 and 3 coordinates representing its latitude, longitude and altitude.

The array declaration will resemble the following:

int [] [] [] ac = new int [4][12][3];

where the first subscript (0..3) is a sector number, the second subscript is the aircraft ID number (0..11) per sector and the third subscript values are the location identifiers 0-latitude, 1-longitude and 2-altitude of the ac. Lat and long will be integer values between 1 and 128 while altitude will be an integer value between 1 and 350 (representing hundreds of feet). Thus a variable such as ac[2][7][2] will contain the number-2 value (altitude) for the number-7 aircraft in the number-2 sector.

The values of each subscript will be generated randomly since there will be 4 sectors of 12 aircraft each and 3 location values for each. Thus there will be 144 location values (48 latitudes, 48 longitudes and 48 altitudes) and 144 subscript values to locate the data in the array.

Since there are 4 sectors, no single controller will care about the aircraft in neighboring sectors so the program will prompt the user for a sector number between 1 and 4 (which will be converted to a subscript between 0 and 3). The result should be a list of text-lines, resembling the following:

Sector 2

Ac 1 Lat 17, Long 46, Alt 140

Near01 Ac 6 Lat 17, Long 42, Alt 140

Near02 Ac 11

Near03 Ac 4

Ac 2

Lab Exercise 06.2

Coordinate Geometry

PLEASE USE JAVA

The purpose of this exercise is to demonstrate class reusability by creating a class that is useful in a variety of contexts. You will design and code a class named Point which can represent a geometric point with x- , y- and z-coordinates.

The class will contain

A private, class-level variable, a String, which will be the points ID.

Three private, class-level integer variables x, y and z that represent the coordinates of the point.

A no-argument (default) constructor that initializes x, y and z with 0 values.

A constructor that accepts three arguments and initializes x, y and z with those values.

A getX( ) method, a getY( ) method and a getZ() method.

A getID( ) method

A method named distance that returns the distance from this point to another point.

public int distance( point p);

I have written a main to test your class. This main method will test the point class and all of its methods by generating an ArrayList of 8 points (at x, y and z values -15 to +15).

The test program will supply pairs of points by using two String values, (ID names for two points). The program will then display the distance between the two specified points. This will be done for a number of point-pairs.

Testing

Files:

Main.java supplied by blackboard

Point.java supplied by you

This is the Main.java

import java.util.ArrayList; import javax.swing.JOptionPane; public class Main { private static final int N_POINTS = 13; private static final int N_DISTANCES = 7; private static final int N_USER_PICKS = 3; private static ArrayList geog = new ArrayList<>(); public static void main(String[]args) { Point p; String name; System.out.println(" populate the list of points "); for (int i=0; i 

Lab Exercise 06.3

Square Root

PLEASE USE JAVA

This exercise is intended to give you experience with throwing and handling exceptions. The job will be to calculate the approximate square root of a number. The main program will generate calls to the sqrt( ) method and will display the answers. The sqrt( ) method will be written using the algorithm as follows:

The approximate square root may be calculated by repeatedly performing a calculation, using the following formula;

nextGuess = ( previousGuess + ( num / previousGuess ) ) / 2

When nextGuess and previousGuess are almost identical, nextGuess is the required square root. The previousGuess to start may be any positive value. After each calculation you will compare nextGuess and previousGuess and if the difference is less than a user-supplied permissible deviation (ex: 0.0001) then nextGuess is the approximate square root of num. If not, then the value of nextGuess is copied to previousGuess and the calculation is done again.

Testing:

If an invalid (negative) argument is sent to the square root method, your program should throw an IllegalArgumentException. Catch this exception in your main method, inform the user of the specific cause of the error and allow the user to try again.

Invalid arguments;

Negative numbers

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Step: 3

blur-text-image

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

Guide To Client Server Databases

Authors: Joe Salemi

2nd Edition

1562763105, 978-1562763107

More Books

Students also viewed these Databases questions

Question

Choose natural conversational words

Answered: 1 week ago