/**
* Compute shortest paths in a graph.
*
* Your constructor should compute the actual shortest paths and maintain all the information needed to reconstruct them. The returnPath() function should use this information to return the appropriate path of edge ID's from the start to the given end.
*
* Note that the start and end ID's should be mapped to vertices using the graph's get() function.
*/
class ShortestPaths {
Multigraph graph;
final int INF = Integer.MAX_VALUE;
PriorityQueue<Integer> Q;
[Code] ....
I followed someone else psuedocode very closely but for whatever reason, my edge[] array is just full of null data, which means I can't actually return the shortest path. Why that's happening/how to fix it? Maybe I'm not understanding dijstra's correctly.
I am using the shortest path algorithm to determine the connection between individuals within a given array. The array is written into the code and not read from external files.
When I am having problem is .. i am having problems how to prompt the user for the starting point or vertex and read that prompt to determine the starting point in the array. I know that this code :
computePaths(v0);
determines the starting point. i want to read "v0" from the user prompt.
First and second numbers are in order source and destination points.
First and second numbers in another each line represent edges. Third one is wage of each edge.
My code looks as follows:
import java.util.*; import java.io.*; class Vertex implements Comparable<Vertex> { public int name = 0; public ArrayList<Edge> adjacencies = new ArrayList<Edge>(); public double minDistance = Double.POSITIVE_INFINITY; public Vertex previous;
I was given some code by a professor to add some features to as part of an assignment. However, the code itself doesn't seem to work.
import java.util.HashSet; import java.util.InputMismatchException; import java.util.PriorityQueue; import java.util.Scanner; import java.util.Set; public class DijkstraPriorityQueue
[Code] ....
The method to find minimum distance is nonfunctional...I receive an error that the types are incompatible. I can't do the assignment if the base code doesn't work to begin with...
I am trying to program the A star algorithm using JButtons. Now I have some tweaking to do but I have to get past the errors first.
I am getting the following errors:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at AStar.findEndButton(AStar.java:40) at Screen$1.actionPerformed(Screen.java:59) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
[Code] ....
In my AStar class you will see these buttons which is an instance of matrixButtons
I have read through some of the posts on insert sort /arrays and see close but not exactly what I'm looking for. I don't want to use a library to do work for me, I want to do it myself and understand it.
OrderedArrayList.java // import static org.junit.Assert.assertEquals; public class OrderedArrayList<T extends Comparable<T>> { // T is a variable that contains a class type, array of T things private T[] arrayA; // changed to private per example private T[] arrayB; int numElements = 0;// number of elements full (not null), used in multiple methods. numElement -1 = back
I'm trying to set a variable to point to the last full cell of an array and then create a new larger array and then have the variable be updated to point to the new array's last full cell index value.
a) Should the variable be declared static? b) What would be the best initial value to set this variable to? Shouldn't it correspond to a <for> loop index rather than a solid integer?
private lastfullcell = a[i]; private int [] a;
c) How would you update <lastfullcell> because if you passed the index through a method's loop index isn't the array index value garbage collected after the method completes?
So I was just wondering if it's possible to create a program with JAVA that uses an algorithm to summarize data inputed. I've never done something like this before, If this is not possible with Java is it possible with C++ or any other language??
I have table data I'm trying to read . However one column is populated with the word "null". I guess java does not like dealing with the word null and throws errors.
When I try a block like : if ( rsrow.getString(insCol) = "null") {
I get and error .
If I try :
cmp = rsrow.getString(insCol);If I try:If I try: if (cmp = "null") {
I get an error
If I try to use a replace function like:
System.out.println(cmp.replace("null", "0"));
Just to see if replace works I get and error.
What is the BEST way to replace this string value with something like "0" when I come across it with out jave throwing an error? I want it such that every time I come across the word "null" I can repalce it with "0".
I'am new to java, this question may have been asked earlier but I'm not getting the exact answer.I want to add data from database into at and display it through jsp. But empty or null values is shown i.e no data is being displayed and when I execute the same sql query which is used in code in sql server then required output is displayed. My java code is:
Java Code:
public List < Alarm_Bean > get_Count(String system_Name) { if (system_Name.equals("MPS")) { try { con = getConnection(); stmt = con.createStatement();
I am trying to export data from a jtable to a pdf report but every time i try running the code it gives me this exception:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at GUI.QC_receiving_book.printButtonActionPerformed(QC_receiving_book.java:309) at GUI.QC_receiving_book.access$600(QC_receiving_book.java:26) at GUI.QC_receiving_book$7.actionPerformed(QC_receiving_book.java:165) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
[Code] ....
I tried avoiding the null exception by using the if statement but it didn't work. The row I choose from the table is full meaning there are no empty attributes. and all the data are imported from a mysql database to the table as String so there can't be any casting errors.
This is the part of the source code with the problem and i will also post the printing method. I tried debugging the class and when stepping into the first if statement it opened the jTable.java file and pointed at the getSelectedRow() method and this sentence "variable information not available.source compiled without -g option"
private void printButtonActionPerformed(java.awt.event.ActionEvent evt) { if(samplesTable.getSelectedRow() >= 0){ int row = samplesTable.getSelectedRow(); System.out.println(row); for(int x=0;x<samplesTable.getColumnCount();x++){ String value = samplesTable.getModel().getValueAt(row, x).toString();
How would I go about inputting the negative values in the array in case 1 the array comes from the user, case 2 from the text file? The sum prints perfectly fine with positive values but if I input negative values it just completely ignores them.
case 1: int sum; System.out.print("Enter list of comma-delimeted integers: "); Scanner scan = new Scanner(System.in); String input2=scan.next(); String[] num = input2.split(","); int[] a= new int[num.length];
I am working with an Adjacency Matrix to try to find the MST of a graph. Along the way I have hit a snag that I am not sure how to get around. When running the program I will parse through each row of the matrix and find the smallest weight. However when trying to reset the row at the end of the lowest sort I cannot move to the next row.
The graph looks like this:
My Matrix was created from the graph and I have determined by starting at Vertex W my path should looks like this: W->R->D->H->G->S->C->B->A
What would be a good and simple algorithm to find the shortest route between two points in a 2D array[grid] ? There can be certain obstacles in the grid i.e. some of the cells may be inaccessible. I tried googling for it and found that A* is the best for this but I am just a beginner and would like to start with something much simpler.
Is there a better way to remove null values from an array than what I have tried? This works just fine, but I just get the feeling that there is a better way to do this, without using the JCF.
private static String[] removeNullValues(String[] list){ int count = 0; for(int i = 0; i < list.length; i++){ if(list[i] == null) count++;
[Code] ....
I technically dont need to remove the null values for the project that I'm working on (since I just print it out and I can avoid null values with a simple statement like
I am trying to return an array and I keep getting a null error. The below class sets the material numbers into an array and should return that array if called :
public class Jobs { private int[] materialsNumber; //change to parts and create another class that gets the materials for the parts public int[] job1() { materialsNumber[0] = 11960120;
[Code] ....
I later try to call the method. The program executes but stops after I println "test in loop"
public class PurchaseOrdersToParts { private Jobs job = new Jobs(); int[] getPartsForPurchaseOrder(BigDecimal purchaseOrder) { System.out.println("inside getparts"); BigDecimal testNum = new BigDecimal(123.0);
[Code] ....
This is the method that is calling the method in the GenerateOrdersToParts class
private PurchaseOrdersToParts purchaseOrdersToParts = new PurchaseOrdersToParts(); @Inject PoRepository poRepository; public GenerateShopJobTickets() {
I'm working on a program to create a blackjack game using objects (one for card, deck. and hand). Withing my hand object I am trying to add cards to the hand but it is only adding the last card i try to add and giving null values for the the ones before.
class BlackJackHand { private BlackJackCard [] hand; public void addToHand(BlackJackCard c) { if (hand == null) { BlackJackCard [] tempHand = new BlackJackCard[1]; tempHand[0] = c; hand = tempHand;
[Code] ....
What I want this section to do is add cards to the current hand. I was intending for it the hand to be null at first and the if(hand == null) piece to add the card the first time and then the else piece would be used when the hand already has at leas one card. I want the else section to create a temporary array that is one larger than my current hand, copy the cards from the old hand to the new hand, and then add a new card to the last space before rewriting the old hand as what the temporary hand is.
The code I am using to test if the addToHand() is working is
class BlackJackTest { public static void main (String[]args) { BlackJackCard c1= new BlackJackCard(1,0); BlackJackCard c2= new BlackJackCard(1,4); BlackJackCard c3= new BlackJackCard(1,5); BlackJackHand h1 = new BlackJackHand();
[Code] .....
BlackJackCard has the parameters (int suit, int value)
This should print: ace of clubs 4 of clubs 5 of clubs
I have a file which contains certain positions ([a][b]) that require to be placed in a certain multi-dimensional array. For example I might have an array String[][] that is a size of 6x6 but only have values in positions [2][1] and [3][2]. Because it is important for me to maintain the given array size and also do certain actions with the given positions I cannot modify the size. In addition I need to count the surrounding neighbors each element has (including elements that are null). However because some of my further code cant process with null elements I need to remove all null elements with " " (blank).
I am not sure how this is done or if it's even possible. If it is not possible how can I do something as close as possible to my needs?
I've a vertical-bar-delimited file where most elements contain text, some contain whitespace, and some are empty. Examples:
62RG|fe|Pencil Financial Group, LLC||doug@pencil.com|||85637889|Cross, Ben|bcross@godaddy.net|Bernard|Cross|Ben||315 One Tree Hill Terrace|Lafayette|LA
String str_arry = innline.split( "|", 17); lisst.add( new Contact( str_arry));
and my Contact class has the constructor
public Contact( String[] str_arry) { for( int ii = 0 ; ii < str_arry.length ; ii++ ) { if( str_arry[ii].matches("^s+$")) { str_arry[ii] = null; System.out.println("hit a null");
[Code]...
I expect the for-loop in the constructor to find any elements containing whitespace characters and set them to null for subsequent assignment.And when the code runs I do see some hit-statements pop up, so the detecting part is working.
But when I then process the list and access a Contact object and test fields for nulls I don't find any ie
if( aContactObj.getfFCity() == null) System.out.println("city is null");
never prints when it should.
What's the trick? Or is my approach wrong and if so what should it be?
Question 1: I am working on an assignment where I have to remove an item from a String array (see code below). When I try to remove an item after entering it I get the following error "java.lang.NullPointerException." I am not sure how to correct this error.
Question 2: In addition, I am having trouble figuring out how to count the number of occurrences of each string in the array and print the counts. I've been looking at other posts but they are more advanced and I have not yet learned how to use some of the tools they are referring to.
private void removeFlower(String flowerPack[]) { // TODO: Remove a flower that is specified by the user Scanner input=new Scanner(System.in); System.out.println(); System.out.println("Please enter the name of the flower you would like to remove:
I'm trying to make a canteen class that holds water. It holds two quarts of water and two quarts is 100%.
public double maxVolume; public int percentFull;
Right now the Canteen is empty.
public void Canteen() { percentFull=0; maxVolume=0; }
And right now I'm trying to make a constructor that specifies the amount of liquid the canteen can hold and specifies the percent full.
public Canteen(double maxVolume, int percentFull) { }
Should I make this second Canteen an integer, a double, or something else? Also, how do I make sure the Canteen never reaches higher than 100%. I'm also curious how I can keep maxVolume and percentFull connected so the % of water is consistent with the number of quarts(2) the Canteen can hold.
public class Test { public static void main(String[] args) { Car c = new Car(); c.setInf("toyota", "red"); System.out.println("name: "+ c.brand + " colour: " + c.colour);
[code]....
Why do I get the result brand null, colour null? I know what null means but what am I missing here?
I am trying to create a JScrollPane with buttons in it, but I noticed that when I try to scroll, the items all move into ONE row at the top of the JScrollPane. How do I have them vertical? Is there something wrong with the way I am setting up the JScrollPane?