CS 146 (Sections 3 and 4): Data Structures and Algorithms, Spring 2008

Programming Assignment Due 5/6 by classtime.

Your program will be called with a command-line filename. You will get all input from that file. The first line of the file will have a single number n, where 0 < n < 1000. That will be followed by n lines each with two integers, separated by a single space. You should interpret those numbers as x and y coordinates for a point on the (Euclidean) plane. The input will not label points, but they are (implicitly) numbered 0 to n-1. All integers will be at least 0 and no more than 999. Following the nth number pair will be another single integer m, which will be followed by m test cases, each a number 0 to n-1. Your goal is to write a program which will figure out how to connect the n points to each other, using the "least ink", where only lines from one point to another are allowed, and connections are made at the points themselves. For each of the test cases, you must tell which other points that point is connected to. Those points should be given in increasing order, all on one line, with a single space separating values on one line.

For example, the input file could contain the following lines:
6
1 3
3 5
2 4
6 3
3 4
9 4
5
0
4
1
3
2

Then, the output should contain:
2
1 2 3
4
4 5
0 4

Here, the very first line of the input file refers to the 6 points (0 through 5), the next 6 lines are the point coordinates, the next line refers to the 5 test cases to follow, and the test cases give the requested output. By adding the smallest length lines between points to connect them, point 0 will be directly connected to point 2. Point 4 will be directly connected to points 1, 2, and 3. Point 1 will be connected to point 4. Point 3 will be connected to points 4 and 5. Finally, point 2 will be connected to points 0 and 4.

In the event that there are multiple answers, you should pick one and use it. (I intend to use only test cases with a unique answer.) Your output should be printed to System.out as in the past. I will be running the programs on a UNIX system, so each line should end with the newline character (\n). (This hasn't been a problem so far.)

Note: both the input and output format are precisely specified for the problem. If you assume a different input format, your program may or may not work correctly. If you give a different output, your solution will be rejected. In the example above, you should be putting out exactly the 9 numbers, with newlines and spaces as specified, but nothing more. The input must be taken from the file specified by the command line argument. Make no assumptions not in the problem specification. I will be automating the testing of your programs, and the automated system will not be very forgiving. It should not take great effort for me to get your code to run. You should be using code that will run with Java 5.

  1. I will run javadoc on your program, so it should be fully documented, including documentation for private methods.
  2. I will also run the style checker on your program, so follow department style guidelines.
  3. You should compile using the Java 5 option. If you use any of the new Java 6 stuff, I will not be able to compile your code. (Sorry.)
  4. Your package name should be edu.sjsu.cs.cs146.
  5. Your file should be named MinInk.java. Your class should be named MinInk, and it should have a main method which will run as requested in the assignment. All other methods are up to you, but should be documented (including documentation of private methods).
  6. Do not assume any other input, or give any other output, other than what is specified above. My automated tester is not very forgiving.
  7. Email your file to me, with the following subject line, replacing the name fields: CS146Spring08: Program 4 Lastname Firstname
  8. The email should empty, other than an attached file of source code, in a single text file named MinInk.java.