I have a database of peoples names linked up to a from to enter a new employee.The form has a previous and next button that should cycle through the employees alphabetically.What im doing the cycle by now is ID which isnt in alphabetical order and just goes by the order they where entered in.
Is there any way to cycle through alphabetically instead? Is running a query each time the next/previous button is pressed the correct way or should it just grab all the names in the array. Theres probably 150 names.
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.
So basically I have an arraylist (names) filled with images.
Now I have a JButton on my GUI and when I click my 'next' button, it's supposed to cycle through to the next image in the arraylist. With this code I am only using it to actually see if it will set the new image, but I keep getting errors thrown at me when im trying to define the new image to be set
String shield = "C:\Documents and Settings\derek\Desktop\shields\" + names.get(1); imgico = new ImageIcon(shield); img.setIcon(imgico);
The error i'm getting is:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at newmay1.makegui$myhandle.actionPerformed(makegui.java:66)
Along with a ton more lines of red text, and i've tried many different ways of doing this.
Even when I simply just output to the console each item in my arraylist, it comes out perfectly as a string.
I'm writing an ESP game code for class. The problem is i cant get it to cycle through the colors after each guess is entered. It stays fixed on the original random number generated.
import java.util.Random; import java.util.Scanner; public class Final1 { String colorInput, computerColor; int computerNum, right, wrong;
[Code] ....
This repeats 10x but the color never changes from the initial random chosen.
Life Cycle Call back methods(init(), destroy(),...) are not transactional by default and expecting this in coming EJB releases (EJB 3.x / EJB 4.x). I was expecting next EJB release along with Java 8, but it stays at 3.2
So we have to create a code that reads in a file that has a huge list of words. Our code has to convert every word to all lower cases and then re-sort alphabetically. I was able to turn everything to lower case, but for the re-sorting I keep getting a null pointer exception on the line of the if statement.
import java.io.*; public class readDict { public static void main(String args[]) { try { System.out.println("Opening the file...");
I have a problem sorting this file alphabetically by second name. Basically, my method sorts each column alphabetically but i would like to sort the file according to the second name.
File: Moe Carl Saul Sergio Rocky Louis Ike Ziken
This is how my method sorts the file:
Ike Carl Moe Louis Rocky Sergio Saul ziken
Instead Moe Carl Rocky Louis Saul Sergio Ike Ziken
At the moment I am studying it and the problem is Taking a range of names in an array and outputting them alphabetically, But for some reason I get an outOfBoundsException. And its starting to get to me. How to put the code in
im new to java and i wanna make a program using java that can add order entries for a restaurant but how to... i was hoping something that would ask to person to input one or two items and before it calculates the total amount to be paid it will ask the guy who inputs the amount whether or not there are additional orders or not before it prints out the total amount... I am pretty sure it will need an if-else statement..
import javax.swing.*; import java.util.Scanner; public class OrderCalc { JFrame.setDefaultLookAndFeelDecorated(true); JFrame aFrame = new JFrame("OrderCalc"); aFrame.setSize(500,250); aFrame.setVisible(true);
I have a project requiring me to build a program having a user input 3 words, sort them alphabetically and output the middle word. I have done some searching and seem to only come back with results for sorting 2 words. I so far have code to get the user input but I am completely lost as to how to sort them alphabetically.
import java.util.Scanner; //The Scanner is in the java.util package. public class MiddleString { public static void main(String [] args){ Scanner input = new Scanner(System.in); //Create a Scanner object. String str1, str2, str3; System.out.println("Please enter three word words : "); //Prompt user to enter the three words
[Code]...
we havnt done arrays yet and I THINK i have to do compareTo.....how to use it?
I have a web form with a field Department. I want to add Sub Departments(unknown number) of one Department and then further Sub Sub Departments(unknown number) of one Sub Department. How I will make a form and how I will add this data in attached database. I have one solution:
One Department field with a button to add any sub department if any. By clicking on button, a new row will be generated with another text field and new button. In this way, it will go on. Tree like structure.
But I have another solution, JSF Tree to add or delete entries on the run time. But the problem is that I am unable to find any example of JSF tree like structure populated from database and in which we can add or delete entries on run time and on the same time these entries may also be stored in database.
I'm having trouble with sorting Strings- 3 strings inputted by user, and I would like to output them in alphabetical order. I've used the str.compareToIgnoreCase method, and then I've tried to loop them through a series of if/ else statements. Everything I've been able to find online (including the forums here) has suggested to use the Comparator class, or to put the strings into an array, and sort list- I really would like to stick with just the String class, and its methods .
The program itself works and compiles, but I am getting logic errors that I have been unable to solve. I'm using IntelliJ Idea, and I've ran it through the built in debugger, about 100+ times (not exaggerating, lol) just to see what it's doing in particular scenarios. For instance, I can get c, a, b, to print out as a,b,c correctly, but a,b,c, will print out as b,a,c.
For me this is kind of like a Sudoku puzzle, or a Rubik's cube! Each time I fix one scenario, it breaks another one, so I don't know if there's a(logic) solution to fix all possible scenarios (abc, acb, bac etc... to all print abc) or if possibly I just need more if statements. I've only pasted in the area where I'm having problems (the if statements). I'm a big fan of the "Next Line" syntax.
(Note: please assume the non relevant content- import Scanner class, main method, etc... I didn't want to paste the entire program.)
System.out.println("Enter the first statement: "); //input.nextLine(); string1 = input.nextLine(); System.out.println("Enter the second statement: "); string2 = input.nextLine(); System.out.println("Enter the third statement: "); string3 = input.nextLine();
I have an editable JTable that has a lot of JComboBox's as cell entries. I would like to be able to "arrow over" to said cell, and with a pressing of either a numerical button or by typing the first letter of the String selection (possibly followed by a second), be able to select the appropriate selection from the cell's JComboBox. I have tried to add a key listener to the JComboBox itself, which works given that I click on said cell and show its menu.
How would I go about ensuring that, when focus is on the cell itself, and I start typing, the appropriate selection is chosen?? (I think this might get into key binding, but I don't know if I have to try it from the scope of JTable, or from that JTable's TableModel (which I have made my custom version of).
Here is what I have so far (everything but SandwichNumber, SandwichName, and Oregano uses JComboBox): [URL] ...., how would I do such key binding?
I think I'm about 90% complete with this program but I'm stuck on my adding entries method. It gives me a runtime error which says:
Enter the name: Bill Exception in thread "main" java.lang.NullPointerException at Phonebook.addEntry(Phonebook.java:70) at Phonebook.main(Phonebook.java:49)
Here is my code: /* * This program asks the user for input for a name, phone number and notes up * to 200 entries. It stores every contact in a file. Type 'h' for help while * running this program. */ import java.util.Scanner; import java.io.*;
Assignment: Develop a GUI-based program to read the entries of a matrix from a text file. The first number is the number of rows; the second number is the number of columns. The remaining numbers are integers between 1 and 9 in row by row order. Scan the matrix, highlight (display the entries in different color) all cells that form a group of five cells with the same value horizontally, vertically or diagonally.
Example of text(.txt) file: 7 7 3623161 3666669 3936293 3594955 3289867 2493998 1399998
Example of output: 3623161 3666669 3936293 3594955 3289867 2493998 1399998
* ^^this would be what it would look like when displayed in the GUI. But it would be colored. Anything that has 5 in a row ...My Class File:
EX. 0=black(when there is no combo. of 5)1=blue(horizantal combo of 5)2=red(vertical combo of 5)3=green(right diagnol combo of 5)4=purple(left diagol combo of 5)
I have a program for a phone directory. It needs to add, delete, append, and edit telephone records. I've gotten it to write and search the files. Just need to get it to delete and edit them.
I have a 2d array that i am manipulating. In my class i have a constructor that takes the dimensions of the array and within th econstructor i need to randomly fill the array. However, when i try to manipulate it in the test program, all that prints out are the default values.
here is the class
import java.util.*; import java.lang.Math; import java.util.Arrays; import java.util.Random; class SummerStats
[Code] .....
And here is the printout
Enter number of rows(people): 3 Enter number of columns(years): 3 Enter number of person to find sum salary: 1 Enter year to find Max salary of that year: 1 [] [] The max salary is at index: (0, 0, ) The largest salary ocurred in year: 0 The sum of person 1 is: 0.0 The total of all salaries is: $0.0 The max salary in year 1 is: 0.0 The average salaries for each year: 0.0, 0.0, 0.0,
The total salary for each person is recorded below.
And the last method called doesn't finish or printout ie the program doesnt end
I have a problem with this application , I have a button that allows users to delete entry's from the array list, but i've noticed when i go back and click display entry's the correct entry has not been deleted.....for example if i enter a,1,2 then b,1,2, then c,1,2 in fields, then delete c,1,2 when i actually go to display the data entered a,1,2 will be gone not the one i entered.
So it seems to be deleting the entry at index 0 of the array list no matter what and not the chosen item..Delete Button Code
private void deleteBtnActionPerformed(java.awt.event.ActionEvent evt) { if (numTf.getText().equals("") || nameTf.getText().equals("") || yearTf.getText().equals("")) { JOptionPane.showMessageDialog(null, "All fields must be full"); } else if (count == 0)
Write an interface Directory to manipulate entries in a telephone directory for the University. The interface must support the following operations:
1) The ability to insert new entries into the directory. Entries should be stored in alphabetical order of surname. 2) Delete entries from the directory either by name or number 3) Provide a lookup method that will find the extension no of a member of staff given his/her name. You should try to make this method run as efficiently as possible. 4) Change a person's telephone number 5) Print the telephone directory in a neatly tabulated fashion.
Write a class ArrayDirectory that implements this interface using an array to store the telephone directory information. The class must store the surname and initial for each member of staff and their telephone extension (a four digit number which may start with a zero). You may find it useful to define a class Entry to store information about individual entries. The entries should be read into the array from a text file consisting of multiple lines in the following format:
Surname<tab>Initials<tab>Telephone extension
Write a main program that reads in data from a file and then tests all the methods of your class interface. Note it is not necessary to write data back to disk (even if it has changed) in this project.
For data insertion and lookup, you should measure the performance for the average case (e.g. looking up a record in the middle of the data). To do this you can use the static method System.currentTimeMillis() which returns the time in milliseconds. To get an accurate measure of the time to perform an operation it is a good idea to perform each operation 1000 (or even 10000) times and measure the time taken. This will remove any problems due to the system clock having a coarse granularity (not ticking very often). Make sure you only time the method and not any input/output associated with it. Your documentation should include a discussion of these results.
Part 2
You decide that your solution to part 1 may be too slow to be useful when used with a real large telephone directory and make the following changes to attempt to improve the performance of your program:
1). Provide a second implementation (ListDirectory) of the Directory interface using the Java Collections List interface and LinkedList classes. 2). The changes in 1) should make adding, deleting and modifying records more efficientbut will probably reduce the time to lookup numbers. To overcome this you use a technique called hashing. Instead of storing all the records on one list you use a series of lists. The data for all people whose surname begins with "A" is stored on the first list, records for all people whose surname begins with "B" on a second list and so on. Write a third implementation (HashDirectory) of the Directory interface using this technique.
Again, you should measure the performance for the best, worst and average cases of implementations 1) and 2) above. Compare the efficiency of each of the 3 implementations in your documentation.
Part 3
Choose one of your 3 implementations from Parts 1 and 2 and embed it in a graphical user interface that allows users to perform all the methods in the Directory interface using a mouse and keyboard appropriately.
this is the following task i am trying to do. Write an interface Directory to manipulate entries in a telephone directory for the University. The interface must support the following operations:
1) The ability to insert new entries into the directory. Entries should be stored in alphabetical order of surname. 2) Delete entries from the directory either by name or number 3) Provide a lookup method that will find the extension no of a member of staff given his/her name. You should try to make this method run as efficiently as possible. 4) Change a person's telephone number 5) Print the telephone directory in a neatly tabulated fashion.
Write a class ArrayDirectory that implements this interface using an array to store the telephone directory information. The class must store the surname and initial for each member of staff and their telephone extension (a four digit number which may start with a zero). You may find it useful to define a class Entry to store information about individual entries. The entries should be read into the array from a text file consisting of multiple lines in the following format:
Surname<tab>Initials<tab>Telephone extension
The part that i am stuck on is trying to do the entry method, delete entries method, loop up method, change persons telephone number and be able to print it.
I remember, it's possible to collect multiple parameters from each line in a .txt file (with commas used as delimiters to separate each parameter on each line). My EmployeeData.txt file looks like this:
The validation of making sure the employee uses the correct format while entering his employee number is just the first part. I also need to add validation code to make sure his employee number matches one of the ones in the EmployeeData.txt file (shown earlier above).
I am trying out jsp and servlets now for the first time. I have to insert two data, car code and car name into a mysql table. I got those details using jsp but if I use form, it redirects to another page for insertion. I want the data to be inserted and still remain in same jsp page. I am thinking of using onClick from javascript but as I googled this many places have said it is a bad idea to use jsp inside javascript. If so how can we insert data to mysql table without redirecting to another page?