Question
[JAVA][FIX ERRORS] import java.util.*; import java.lang.*; import java.io.*; import java.awt.Graphics; import javax.swing.JFrame; import javax.swing.JPanel; public class Exercise extends JFrame { public static void main(String[] args)
[JAVA][FIX ERRORS]
import java.util.*; import java.lang.*; import java.io.*; import java.awt.Graphics; import javax.swing.JFrame; import javax.swing.JPanel;
public class Exercise extends JFrame {
public static void main(String[] args) throws FileNotFoundException {
Scanner input = new Scanner(System.in); System.out.print("Enter a file name: "); File file = new File(input.nextLine());
if (!file.exists()) { System.out.println("File does not exist"); System.exit(0); }
System.out.print("Enter two vertices (integer indexes): "); int vertex1 = input.nextInt(); int vertex2 = input.nextInt();
Scanner inFile = new Scanner(file); // Read the number of vertices String s = inFile.nextLine(); int numberOfVertices = Integer.parseInt(s); System.out.println("The number of vertices is " + numberOfVertices);
List
while (inFile.hasNext()) { String [] tokens = null; s = inFile.nextLine(); String[] triplet = s.split("[\\|]"); //this will always overwrite tokens //And triplet has 4 positions (0,1,2,3) so you cant just have int u,v and w /* for (String i : triplet){ tokens = i.split("[,]"); } */
int u = Integer.parseInt(tokens[0].trim()); int v = Integer.parseInt(tokens[1].trim()); int w = Integer.parseInt(tokens[2].trim());
} } }
class GraphView extends JPanel { private int position; private int edge; //construct a graphview object public GraphView() { } //construct a graphview object with specified position and edge public GraphView(int position, int edge) { } protected void paintComponent(Graphics g) { super.paintComponent(g); Scanner scan = new Scanner(new File("myFile.txt")); // scanner to read file String line = scan.nextLine(); // read first line int nbLine = Integer.parseInt(line); // get number of lines ArrayList
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started