Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help doing this Java Code Specification: Start with the given Java program prog340, which lets you select a file to read from your computer,

Need help doing this Java Code

image text in transcribedimage text in transcribed

Specification: Start with the given Java program "prog340", which lets you select a file to read from your computer, reads the file, and interprets that file as the specification of a graph.' Then enhance it to print out the distance of the Traveling Salesperson (TSP) tour starting and ending at the start node (the node with value S), where the tour traverses the nodes in order, wrapping around after the last city. The prog340 handout describes the format of the input file for this and all program deliverables. As will always be the case in this class, the program must be written in Java and must run on the University Windows computer systems. To ensure this I strongly recommend that you: 1. Use only Oracle Java 8 SE and earlier constructs, and 2. Test it on the University systems before submission if you have any doubts about its ability to run on the University Windows. Submit the Java source code to the open Deliverable A submission folder. You may submit either the source code or a full Eclipse package. Output: Here is sample output for one graph. val Atl Boschi Dal Den LA Mia Min NY SF Sea Was Atlanta 0 957 581 725 1220 1942 608 898 752 2155 2201 538 Boston 957 0 859 1571 1783 2594 1285 1127 207 2719 2505 420 Chicago 581 859 0 803 928 1736 1185 354 718 1876 1758 601 Dallas 725 1571 803 0 667 1248 1116 851 1384 1494 1698 1190 Denver - 1220 1783 928 667 0 812 1736 697 1645 957 1033 1507 LosAngeles S 1942 2594 1736 1248 812 0 2357 1500 2451 313 923 2301 Miami - 608 1285 1185 1116 1736 2357 0 1505 1097 2611 2755 917 Minneapolis - 898 1127 354 851 697 1500 1505 0 1024 1597 1415 940 NewYork - 752 207 718 1384 1645 2451 1097 1024 02594 2430 213 San Francisco - 2155 2719 1876 1494 957 313 2611 1597 2594 0 691 2464 Seattle - 2201 2505 1758 1698 1033 923 2755 1415 2430 691 02354 Washington - 538 420 601 1190 1507 2301 917 940 213 2464 2354 0 The output for this file should be: TSP tour: LA -> Mia -> Min -> NY -> SF -> Sea -> Was -> Atl -> Bos -> Chi -> Dal -> Den -> LA Distance = 15161 If for a graph, that desired tour is not possible, so state. Thus this input file: - A val - S OU? A - 4 B 3 - C 2 5 D - 3 E 5 - - 6 - 6 5 4 - 2 1 Yields output: TSP tour: Is not possible. 10 import java.io.*;. 4 6 public class DelivA { File inputFile; File outputFile; PrintWriter output; Graph g; 10 12 130 14 public DelivAC File in, Graph gr ) { input File = in; g = gr; // Get output file name. String inputFileName = inputFile.toString(); String baseFileName = inputFileName.substring( 0, inputFileName. len String outputFileName = baseFileName. concat( "_out.txt" ); outputFile = new File( outputFileName); if ( outputFile.exists()) { // For retests outputFile.delete(); try { output = new PrintWriter(outputFile); catch (Exception x ) { System.err.format("Exception: %s%n", x); System.exit(0); System.out.println( "DelivA: To be implemented"); output.println( "DelivA: To be implemented"); output. flush(); 38 } Specification: Start with the given Java program "prog340", which lets you select a file to read from your computer, reads the file, and interprets that file as the specification of a graph.' Then enhance it to print out the distance of the Traveling Salesperson (TSP) tour starting and ending at the start node (the node with value S), where the tour traverses the nodes in order, wrapping around after the last city. The prog340 handout describes the format of the input file for this and all program deliverables. As will always be the case in this class, the program must be written in Java and must run on the University Windows computer systems. To ensure this I strongly recommend that you: 1. Use only Oracle Java 8 SE and earlier constructs, and 2. Test it on the University systems before submission if you have any doubts about its ability to run on the University Windows. Submit the Java source code to the open Deliverable A submission folder. You may submit either the source code or a full Eclipse package. Output: Here is sample output for one graph. val Atl Boschi Dal Den LA Mia Min NY SF Sea Was Atlanta 0 957 581 725 1220 1942 608 898 752 2155 2201 538 Boston 957 0 859 1571 1783 2594 1285 1127 207 2719 2505 420 Chicago 581 859 0 803 928 1736 1185 354 718 1876 1758 601 Dallas 725 1571 803 0 667 1248 1116 851 1384 1494 1698 1190 Denver - 1220 1783 928 667 0 812 1736 697 1645 957 1033 1507 LosAngeles S 1942 2594 1736 1248 812 0 2357 1500 2451 313 923 2301 Miami - 608 1285 1185 1116 1736 2357 0 1505 1097 2611 2755 917 Minneapolis - 898 1127 354 851 697 1500 1505 0 1024 1597 1415 940 NewYork - 752 207 718 1384 1645 2451 1097 1024 02594 2430 213 San Francisco - 2155 2719 1876 1494 957 313 2611 1597 2594 0 691 2464 Seattle - 2201 2505 1758 1698 1033 923 2755 1415 2430 691 02354 Washington - 538 420 601 1190 1507 2301 917 940 213 2464 2354 0 The output for this file should be: TSP tour: LA -> Mia -> Min -> NY -> SF -> Sea -> Was -> Atl -> Bos -> Chi -> Dal -> Den -> LA Distance = 15161 If for a graph, that desired tour is not possible, so state. Thus this input file: - A val - S OU? A - 4 B 3 - C 2 5 D - 3 E 5 - - 6 - 6 5 4 - 2 1 Yields output: TSP tour: Is not possible. 10 import java.io.*;. 4 6 public class DelivA { File inputFile; File outputFile; PrintWriter output; Graph g; 10 12 130 14 public DelivAC File in, Graph gr ) { input File = in; g = gr; // Get output file name. String inputFileName = inputFile.toString(); String baseFileName = inputFileName.substring( 0, inputFileName. len String outputFileName = baseFileName. concat( "_out.txt" ); outputFile = new File( outputFileName); if ( outputFile.exists()) { // For retests outputFile.delete(); try { output = new PrintWriter(outputFile); catch (Exception x ) { System.err.format("Exception: %s%n", x); System.exit(0); System.out.println( "DelivA: To be implemented"); output.println( "DelivA: To be implemented"); output. flush(); 38 }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions

Question

What was the positive value of Max Weber's model of "bureaucracy?"

Answered: 1 week ago