Question

How can I solved my Java Program for DelivC

ProgramIntro.pngProgramIntro1.pngProgramIntro2.pngProgram1.png

//Graph Class:
import java.util.ArrayList;
//Graph is a class whose objects represent graphs.
 public class Graph {
    ArrayList<Node> nodeList;
    ArrayList<Edge> edgeList;
   
    public Graph() {
        nodeList = new ArrayList<Node>();
        edgeList = new ArrayList<Edge>();
   
    }
   
    public ArrayList<Node> getNodeList() {
        return nodeList;
   }
   public ArrayList<Edge> getEdgeList() {
        return edgeList;
   }
   public void addNode(Node n) {
        nodeList.add(n);
   }
   public void addEdge(Edge e) {
        edgeList.add(e);
   }
   public String toString() {
        String s = "Graph g.\n";
        if (nodeList.size() > 0) {
            for (Node n : nodeList) {
        // Print node info
        String t = "\nNode " + n.getName() + ", abbrev " + n.getAbbrev() + ", value " + n.getVal() + "\n";
        s = s.concat(t);
        }
        s = s.concat("\n");
            }
        return s;
    }
 }

// Node Class:
import java.util.ArrayList;
 // Node is a class whose objects represent nodes (a.k.a., vertices) in the graph.
 public class Node {
   String name;
    String val; // The value of the Node
    String abbrev; // The abbreviation for the Node
    ArrayList<Edge> outgoingEdges;
    ArrayList<Edge> incomingEdges;
   
   
    String color; //Create the color of the TYPE Node List
    int start; //Create the Starting Time
    int end; //Create the Ending Time
   
   
    public Node( String theAbbrev ) {
        setAbbrev( theAbbrev );
        val = null;
        name = null;
        outgoingEdges = new ArrayList<Edge>();
        incomingEdges = new ArrayList<Edge>();
    }
   
    public String getAbbrev() {
        return abbrev;
    }
   
    public String getName() {
        return name;
    }
   
    public String getVal() {
        return val;
    }
   
    public ArrayList<Edge> getOutgoingEdges() {
        return outgoingEdges;
    }
   
    public ArrayList<Edge> getIncomingEdges() {
        return incomingEdges;
    }
   
    public void setAbbrev( String theAbbrev ) {
        abbrev = theAbbrev;
    }
   
    public void setName( String theName ) {
        name = theName;
    }
   
    public void setVal( String theVal ) {
        val = theVal;
    }
   
    public void addOutgoingEdge( Edge e ) {
        outgoingEdges.add( e );
    }
   
    public void addIncomingEdge( Edge e ) {
        incomingEdges.add( e );
    }
   
   
    //Create the Starting Time of the Node
    public int getStartTime() {
        return start;
    }
    //Create the Finshing Time of the Node
    public int getFinishTime() {
        return end;
    }
   public void setColor(String string) {
        color = string;
    }
   public String getColor() {
        return color;
    }
    //Set Starting-Time
    public void setStartTime(int time) {
        start = time;
       
    }
    //Set Finishing-Time
    public void setFinishTime(int time) {
        end = time;
 }
//Edge Class:
//import java.util.*;
// Edge between two nodes
 // Edge is a class whose objects represent edges (a.k.a., arcs) between nodes of the graph.
 public class Edge {
   
    String label;
    int dest;
    int dist;
    Node tail;
    Node head;
   
   //String Type(Forward,Backward,Cross,Tree)
    String name;
   
    public Edge( Node tailNode, Node headNode, String theLabel ) {
        setLabel( theLabel );
        setTail( tailNode );
        setHead( headNode );
    }
   
    public Edge(int dest, int dist,String label,String name)
    {
        //Create the destination Vertex Index
        this.dest = dest;
        this.dist = dist; // Source Vertex index
        this.label=label; // Label of Edge
        this.name= name; // (Locate the Type of Line(F,B,C,T)
        }
   
    public String getLabel() {
        return label;
    }
   
    public Node getTail() {
        return tail;
    }
   
    public Node getHead() {
        return head;
    }
   
    public int getDist() {
        return dist;
    }
   
    public void setLabel( String s ) {
        label = s;
    }
   
    public void setTail( Node n ) {
        tail = n;
    }
   
    public void setHead( Node n ) {
        head = n;
    }
   
    public void setDist( String s ) {
        try {
            dist = Integer.parseInt( s );
        }
        catch ( NumberFormatException nfe ) {
            dist = Integer.MAX_VALUE;
        }
    }
    public String getType() {
        return name;
    }
   public void setType(String string) {
        this.name = string;
    }
 }
//NEED HELP ON IMPLEMENT ON DELIVC CLASS
//DelivC Class (DelivC Need to be implemented) :
import java.io.File;
 import java.io.PrintWriter;
// Class DelivC does the work for deliverable DelivC of the Prog340
public class DelivC {
   File inputFile;
    File outputFile;
    PrintWriter output;
    Graph g;
   
    public DelivC( File in, Graph gr ) {
        inputFile = in;
        g = gr;
       
        // Get output file name.
        String inputFileName = inputFile.toString();
        String baseFileName = inputFileName.substring( 0, inputFileName.length()-4 ); // Strip off ".txt"
        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( "DelivC: To be implemented");
        output.println( "DelivC: To be implemented");
        output.flush();
    }
 }


0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
How can I solved my Java Program for DelivC
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • How to solve my code for my Deliv C program?

    ProgramIntro.pngProgramIntro2.pngProgramIntro1.pngProgram1.pngProgram2.pngGraph Class:import java.util.ArrayList;//Graph is a class whose objects represent graphs. public class Graph {    ArrayList<Node> nodeList;    ArrayList<Edge> edgeList;       public Graph() {        nodeList = new ArrayList<Node>();        edgeList = new ArrayList<Edge>();       }       public ArrayList<Node> getNodeList() {        return nodeList;   }   public ArrayList<Edge> getEdgeList() {        return edgeList;   }   public void addNode(Node n) {        nodeList.add(n);   }   public void addEdge(Edge e) {        edgeList.add(e);   }   public String...

  • How can I get started in this program for this DelivC?

    SpecificationStart with your Java program "prog340" which implements Deliverables A and B.This assignment is based on the definition of the Traveling Salesperson Problem (the TSP): Given a set of cities, you want to find the shortest route that visits every city and ends up back at the original starting city. For the purposes of this problem, every city will be directly reachable from every other city (think flying from city to city).Your goal is to use a non-genetic local search...

  • How to solve and code the following requirements (below) using the JAVA program? 1. Modify the...

    How to solve and code the following requirements (below) using the JAVA program? 1. Modify the FoodProduct Class to implement Edible, add the @Overrride before any methods that were there (get/set methods) that are also in the Edible interface. 2. Modify the CleaningProduct Class to implement Chemical, add the @Overrride before any methods that were there (get/set methods) that are also in the Chemical interface. 3. Create main class to read products from a file, instantiate them, load them into...

  • How would I traverse through this graph? Provide example code, please! class Edge {    int src,...

    How would I traverse through this graph? Provide example code, please! class Edge {    int src, dest;    Edge(int src, int dest)    {        this.src = src;        this.dest = dest;    } }; // class to represent a graph object class Graph {    // A list of lists to represent adjacency list    List<List<Integer>> adj = new ArrayList<>();    // Constructor to construct graph    public Graph(List<Edge> edges)    {        // allocate memory for adjacency list        for (int i = 0; i < edges.size(); i++) {            adj.add(i,...

  • Course,java import java.util.ArrayList; import java.util.Arrays; /* * To change this license header, choose License Headers in...

    Course,java import java.util.ArrayList; import java.util.Arrays; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author fenghui */ public class Course {     private String cName;     private ArrayList<Subject> cores;     private ArrayList<Major> majors;     private ArrayList<Subject> electives;     private int cCredit;          public Course(String n, int cc){         cName = n;         cCredit = cc;         cores = new ArrayList<Subject>(0);         majors =...

  • This is my current output for my program. I am trying to get the output to...

    This is my current output for my program. I am trying to get the output to look like This is my program Student.java import java.awt.GridLayout; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import javax.swing.JFileChooser; public class Student extends javax.swing.JFrame {     BufferedWriter outWriter;     StudentA s[];     public Student() {         StudentGUI();            }     private void StudentGUI() {         jScrollPane3 = new javax.swing.JScrollPane();         inputFileChooser = new javax.swing.JButton();         outputFileChooser = new javax.swing.JButton();         sortFirtsName = new...

  • Help! Not sure how to create this java program to run efficiently. Current code and assignment...

    Help! Not sure how to create this java program to run efficiently. Current code and assignment attached. Assignment :Write a class Movies.java that reads in a movie list file (movies.txt). The file must contain the following fields: name, genre, and time. Provide the user with the options to sort on each field. Allow the user to continue to sort the list until they enter the exit option. ---------------------------------------------------------- import java.util.*; import java.io.*; public class Movies { String movieTitle; String movieGenre;...

  • For this assignment, you will write a program to work with Huffman encoding. Huffman code is...

    For this assignment, you will write a program to work with Huffman encoding. Huffman code is an optimal prefix code, which means no code is the prefix of another code. Most of the code is included. You will need to extend the code to complete three additional methods. In particular, code to actually build the Huffman tree is provided. It uses a data file containing the frequency of occurrence of characters. You will write the following three methods in the...

  • JAVA: How do I output all the data included for each employee? I can only get...

    JAVA: How do I output all the data included for each employee? I can only get it to output the name, monthly salary and annual salary, but only from the Employee.java file, not Salesman.java or Executive.java. Employee.java package project1; public class Employee { private String name; private int monthlySalary; public Employee(String name, int monthlySalary) { this.name = name; this.monthlySalary = monthlySalary; } public int getAnnualSalary() { int totalPay = 0; totalPay = 12 * monthlySalary; return totalPay; } public String...

  • I have a Graph.java which I need to complete four methods in the java file: completeGraph(),...

    I have a Graph.java which I need to complete four methods in the java file: completeGraph(), valence(int vid), DFS(int start), and findPathBFS(int start, int end). I also have a JUnit test file GraphTest.java for you to check your code. Here is Graph.java: import java.util.ArrayList; import java.util.LinkedList; import java.util.Queue; import java.util.Stack; /* Generic vertex class */ class Vertex<T> { public T data; public boolean visited; public Vertex() { data = null; visited = false; } public Vertex(T _data) { data =...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT