Question

How to solve my code for my Deliv C program?

ProgramIntro.png

ProgramIntro2.png

ProgramIntro1.png

Program1.png

Program2.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 to solve my code for my Deliv C program?
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 can I solved my Java Program for DelivC

    //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;...

  • 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,...

  • 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...

  • 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;...

  • 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...

  • 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 =...

  • Create the code for GraphAlgorithm.prim() so that the MST main routine can run properly public class...

    Create the code for GraphAlgorithm.prim() so that the MST main routine can run properly public class MSTmain { public static void main(String[] args) { MyGraph G = new MyGraph(6); G.insertEdge(0, 2, 5); G.insertEdge(2, 0, 5); G.insertEdge(1, 0, 1); G.insertEdge(0, 1, 1); G.insertEdge(0, 5, 8); G.insertEdge(5, 0, 8); G.insertEdge(1, 2, 7); G.insertEdge(2, 1, 7); G.insertEdge(1, 3, 5); G.insertEdge(3, 1, 5); G.insertEdge(2, 3, 1); G.insertEdge(3, 2, 1); G.insertEdge(1, 5, 9); G.insertEdge(5, 1, 9); G.insertEdge(3, 4, 3); G.insertEdge(4, 3, 3); G.insertEdge(4, 2, 7);...

  • Can someone help me with my code.. I cant get an output. It says I do...

    Can someone help me with my code.. I cant get an output. It says I do not have a main method. HELP PLEASE. The instruction are in bold on the bottom of the code. package SteppingStones; //Denisse.Carbo import java.util.Scanner; import java.util.ArrayList; import java.util.List; public class SteppingStone5_Recipe { private String recipeName; private int servings; private List<String> recipeIngredients; private double totalRecipeCalories; public String getRecipeName() { return recipeName; } public void setRecipeName (string recipeName){ this.recipeName = recipeName; } public int getServings() { return...

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