I'm working on a homeowork assignment here URL... and I can't get the graph to work correctly. I'm not really sure how to print the string of names, gender and rank at the point on the graph. Also I'm just wondering if I set up the scanner to find names right.
import java.util.*;
import java.io.*;
import java.awt.*;
public class Names {
public static final int year = 1880;
public static final int decades = 14;
public static final int decadeWidth = 70;
My program has just "File" and "Help" in the menubar when "File" is clicked, there is an exit item that closes when clicked.i want the "About" item in "Help" to open a new window, what's wrong with my code?here is it:
Now my issue is I have a JTable. The first column will contain Date objects all the way to the bottom. I want the JTable to display only the month and year. I created a custom cell renderer, but it appears the cell renderer method "getTableCellRendererComponent" is never called. (I tested it using System.out.println();) Here is my code for setting the cell renderer and the contents of the first column:
MonthYearTableCellRenderer renderer = new MonthYearTableCellRenderer(); tblView.setDefaultRenderer(Date.class, renderer); for(int i = 0; i < 60; i++){ Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_MONTH, 1); cal.add(Calendar.MONTH, i); tableModel.setValueAt(cal.getTime(), i, 0); }
The Date objects are set into the cells of column 0 correctly. The table shows the result of the "toString()" method for each cell in that column.
Prompt for the project is "Write a program that will ask the user for a number of seconds and output the equivalent period of time in days, hours, minutes, and seconds.The program should:
-Use modulo division to calculate the number of days, hours, and minutes. -Use compound operators when making assignments. -Proper formatting and use of comments -Symbolic constants defined as the number of seconds in a minute, hour, and day.
For example: final int sec_in_min = 60;"
public class Mod1 { public static void main (String[] args) { int sec, min, hr, day; final int SEC_IN_MIN = 60; final int SEC_IN_HR = 60 * 60; final int SEC_IN_DAY = 60 * 60 * 24;
I have this code for reading a text file and printing out information about the graph, the program works perfectly but I need to figure out the in degree and out degree of the graph if it is an directed graph. So my question is how would I go about implementing that? I know what in degree and out degree does but in terms of the code I'm not so sure, so I'm thinking if the case of vertex 0,1 the first vertex comes before the second vertex so that would in an in degree right? But how would I do that?
I need to generate a bar chart given the data that is in main. The relative performance of each sorting algorithm with respect to time, number of comparisons, and number of swaps for each data set (e.g., 50,000 –400,000 random integers). Each algorithm will have 5 bars corresponding to the 5 data sets. The height of these bars will depend on the performance of the algorithm for that data set.
I know how to write a bar with normal values like integers but for this I'm not sure because the values for instance comparisons and swaps are not given they are calculated. I just need to know what steps to go about doing that, you can even express them in pseudocode or even just explaining it I don't need the code, I think. Here is the main
public class Main { public static void main(String[] args){ int t= 50000; int t2=100000; int t3=200000; int t4=300000; int t5=400000;
I'm trying to read a text file of a graph and print information about the graph including the order and size of the graph, rather it is a directed or undirected graph, if it is directed the in and out degree, and the and a list of all vertices for which it is adjacent. The problem is the adjacency list is just printing out the list of vertices instead of the adjacency list. Is there something in my code that is problematic? Also I'm unsure of how to go about the in and out degree
"graphs.txt" 6,1 0,2 0,4 1,4 1,5 2,1 2,3 2,5 3,2 3,4 4,1 4,5 5,1 5,3 5,2 import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class AdjList { private Node first; // beginning of list
So I have an array which holds 19 elements, each element represents a value of 'income'. I'm trying to code the graph so that each bar will represent the value of each element of the array (income). I have been given the code ' for (int Bar = 0; Bar < array of values.length; bar++);' however i'm unsure if this is how to do it, or what to add to this code to make it work.
I'm trying to print the number of vertices in a text file on a graph which is the first integer in the file and then the type of graph is an undirected graph for a 0 or a 1 for a directed graph. Right now I'm just trying to print the number of vertices which is a 6 in the text file.
Here's the text file:
6,1 0,2 0,4 1,4 1,5 2,1 2,3 2,5 3,2 3,4 4,1 4,5 5,1 5,3 5,2 Im getting the following error: Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 6, Size: 0 at java.util.ArrayList.rangeCheckForAdd(Unknown Source) at java.util.ArrayList.add(Unknown Source) at Vertices.main(Vertices.java:21)
Then I need to know how to go about reading the next line in the file, do you read it with the nextLine and put it into an arrayList or do I read each index in the graph?
public class Vertices { public static void main(String[] args) throws Exception { Scanner inFile = new Scanner(new File("graphs.txt")); // Read the number of vertices String line = inFile.nextLine(); ArrayList<Integer> list=new ArrayList<Integer>(); String[] data=line.split("[\,]"); int numberofvertices=Integer.parseInt(data[0]); int typeOfGraph=Integer.parseInt(data[1]); list.add(numberofvertices,typeOfGraph); System.out.println("The number of vertices is " + numberofvertices); } }
Before I created the data file are the points of x and y I created a model class that represents the graph. I have a problem with making a function that returns the panel of the graph.
Attached File(s)
data.cvs.txt (726bytes) Number of downloads: 12 chart.txt (3.72K) Number of downloads: 10
A graph consists of vertices and edges that connect vertices. Write a program that reads a graph from a file and displays it on a panel. The first line in the file contains a number that indicates the number of vertices (n). The vertices are labeled as 0, 1, ..., n-1. Each subsequent line, with the format u x y v1, v2, ..., describes that the vertex u is located at position (x, y) with edges (u, v1), (u, v2), etc. Your program prompts the user to enter the name of the file, reads data from the file, and displays the graph on a panel.
A graph is a mathematical structure with vertices and edges that connect the vertices. A graph is a very useful tool for modeling real-world problems. This project is to display the graph. The information for the graph is stored in a file. The number of the vertices n is stored in the first line of the file. The vertices are labeled 0, 1, 2, ..., n-1. The format of each subsequent line is u x y v1, v2, ..., which describes vertex u at location (x, y) and u is connected to vertices v1, v2, etc.
Design:
The program should first read the information about the graph from a file. The program prompts the user to enter the file name and read vertices location information into a two-dimensional array named position, where (position[0][0], position[0][1]) is the x- and y-coordinates for vertex 0. For example, in the sample graph, (position[0][0], position[0][1]) is (30, 30). The program reads the edge information into an array of ArrayList named edge (ArrayList is covered in Chapter 11). For example, in the sample graph, edge[0].Is an ArrayList that contains elements 1 and 2, which indicates that vertex 0 is connected to vertex 1 and vertex 2. position and edge should be created as followed:
int[][] position = new int[n][2]; ArrayList[] edge = new ArrayList[n];
I don't know how to implement the code. I have started but I am not sure how to proceed.
import java.awt.Graphics; import java.util.*; import java.io.*; import javax.swing.JFrame; import javax.swing.JPanel; public class Exercise15_27 extends JFrame {
I have some problem checking if a directed graph has a cycle or not. So I have a given rooted directed graph, and find if there at least one existing cycle.
For example, I have to input the Root Node, followed by a number of nodes, the nodes in the graph, number of edges, and the adjacency list representing the edges. Each entry in the adjacency list contains a pair of nodes. The ordering of the nodes in the pair represents the direction of the edge. An entry A, B means that there is an edge from A to B. Nodes in each pair is separated by a space. One input per line.
And the output should display whether the directed graph has a cycle or not.
Sample input:
A //Root Node 6 //Number of Nodes A //Nodes in Graph B C D E F 6 //Number of edges A B //Adjacency list representing the edges B C C D C F F E E B
Output: Cycle!
Graph Representation:
Based on the illustration above, the graph has one cycle. The cycle exists in nodes B, C, F and E.
I have few values for X and Y axis from the Oracle DB table. SO is there any java technology available to display the values in the form of graph with the valuesfrom the table along X and Y axis and represent it in any form of graph , which we could chose.
I have following methods, which I call from the Event Dispatcher Thread:
public void setTitle(String title) { Platform.runLater(() -> stage.setTitle(title));} public String getTitle() { return stage.getTitle(); // <- Access from outside JFX App Thread ok?}
Is it thread-safe, when the getter-Method just return the value like the example show? Or must I create a Runnable, so stage.getTitle() is called inside the Java Application Thread? How I return the value then?
I want to use graphs in java. Is there any class in java for implementation of graph theory? I most create a graph and run DFS(Depth First Search) algorithm on that.
[URL] I made a program that takes 2 stock values by URL tickers, and now I need it to draw a graph with the values for the 2 stocks, so they can be compared visually. So far my idea was to create 2 arraylists that consist of the values for each stock, so that I can draw the graph so that x always move with 1 step, and y0 is the first coordinate, and y1 is the second, and after that y1 is the first, y2 second etc.
I am building a program that when you enter 1. it allows you to setup an item. However running my code my second if statement runs through.
import java.util.Scanner; public class InventorySystem { public static void main(String [] args) { Scanner input = new Scanner(System.in); int count=0; int inputEntered=0; int numberOfItems=0; double cost=0.00; String item; String description;