Array Doesn't Change From Default Entries
Dec 7, 2014
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
View Replies
ADVERTISEMENT
Jan 22, 2015
I want to programmatically change the default program which an extension is opened in. So .resantic extensions for example to run in my jar file when I double-click on it. I know i need a bat file or exe file because i can't directly run the jar file. But i was wondering if its possible to run it if its an executable jar file. Else i can just make a bat file that runs my program. Also how can i on double click send the path to the file that was clicked in the args[] array so i can open the actual file aswell instead of just opening the program?
View Replies
View Related
Mar 4, 2014
I have Java 6 and Java 7 installed, if i open an applet in any browser it uses the dll's and from the jre7 folder. I would like it to use the jre6 folder, without uninstalling java7. I tried doing this through the java control panel by adding jre6, checking it as enabled and checking off jre7. It didn't make any diffrence.
View Replies
View Related
May 21, 2015
I have a JTable that is being used to display, and edit data from a database. When the user presses the Enter key on the keyboard I want a carriage return to occur in the cell they are typing in. I do not want the cursor to go to the next row which is the default behavior.
View Replies
View Related
Mar 19, 2013
I'm deploying an EAR file on weblogic 10.3.4. The EAR file contains a war file and a jar file that implements web services using EJBs.
The application deploys and is functioning correctly. The application is available from the following URLs:
web application: [URL] ....
web services: [URL] ....
However, I would like configure the deployment to insert the "app1" string into the URL so the application is available like this:
web application: [URL] ....
web services: [URL] ....
I've been looking at some of the configuration options in deployment plans, but can't seem to get anything working.
View Replies
View Related
Apr 28, 2014
Write a program that asks the user for the low and high integer in a range of integers. The program then asks the user for integers to be added up. The program computes two sums:
The sum of integers that are in the range (inclusive), and the sum of integers that are outside of the range. The user signals the end of input with a 0.
Your output should look like this:
Sample input/output
In-range Adder Low end of range: 20
High end of range: 50
Enter data: 21
Enter data: 60
Enter data: 49
Enter data: 30
Enter data: 91
Enter data: 0
Sum of in range values: 100
Sum of out of range values: 151
This is my assignment and below is my code.
import java.util.Scanner;
class InRangeAdder {
public static void main(String[] args) {
Scanner scan = new Scanner (System.in);
int low, high, data=1, rangesum=0, outrangesum=0;
[Code] ....
The problem is that the program simply gives an output of 0 for both "rangesum" and "outrangesum". I don't quite understand why that is. Also i have a quick question, the program needs me to end the program when the value of data is 0 but in order to initialize it I need to give it a value. Usually I would give it a value of 0 like I have for rangesum and outrangesum but if I do the program does not run till the loop as it considers the value of data to be 0 and ends the program right away. What would be a work around to this and when do I need to have a value to initialize an integer? for example, I do not need a value for low and high. Is this because the program recognizes that a value is going to be defined but cannot do that for the other integers as they are inside a loop?
View Replies
View Related
Feb 10, 2015
the problem was :
i wrote it on paper with my examples.and just for laughts , i uploaded another picture that dont belong to my problem. its just my way to understand binary search tree implementation , so i wanted so share.just for laught : looks like the map of the universe.
now my problem : why after i changed Current to Current.left, Parent still has the value of root. i draw and wrote it on a paper. to be clear as possible - picture 2 :
View Replies
View Related
Oct 15, 2014
I have noticed a strange behavior of Combobox element. The number of visible rows is not the same established by setVisibleRowCount() method. It happens when changing the items list dynamically. The following example reproduces it. I think it is Javafx 8 bug. I have tried unsuccessfully to trigger some event indirectly to refresh the combobox drop down.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class TestComboBox extends Application {
private int count;
[Code] .....
View Replies
View Related
Aug 15, 2014
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)
[code]....
View Replies
View Related
Feb 24, 2014
Java Code:
import java.io.*;
import java.util.Scanner;
public class asciiFile {
int height;
int width;
Scanner input;
char[][] poop;
public asciiFile(File f) throws FileNotFoundException{ //constructor
[code]...
The constructor is supposed to take an ASCII file, take the numbers in the file, and populate a 2D array with the numbers in the file.
For some reason, the for loop I use to populate the array works outside of the constructor. When I put it in one of the methods, it runs normally. However, when I keep it in the constructor, I get the following error:
Exception in thread "main" java.lang.NullPointerException
at asciiFile.<init>(asciiFile.java:16)
at main.main(main.java:6)
View Replies
View Related
Feb 14, 2014
I need to change the program below to an "array"....
public class RecursiveFibonacci {
public int fibonacci(int n) {
int result;
if (n == 1 || n == 2)
result = 1;
else {
int n1 = fibonacci(n-1);
int n2 = fibonacci(n-2);
[code]....
View Replies
View Related
Dec 11, 2014
I am trying to change an input String to an array of characters, but it only stores the word before the space into the array. Here is the code:
Scanner scanner = new Scanner(System.in);
System.out.println(" Enter text: " );
String text = scanner.next();
char[] characterArray = text.toCharArray(); // convert string to array of characters
String char = "";
for( i = 0; i < characterArray.length; i++) {
char = char + characterArray[i]
} System.out.println(char);
Just typing hello gives me hello, but when I type hello world it does not type in the word "world".I am trying to change an input String to an array of characters, but it only stores the word before the space into the array.Here is the code:
Scanner scanner = new Scanner(System.in);
System.out.println(" Enter text: " );
String text = scanner.next();
char[] characterArray = text.toCharArray(); // convert string to array of characters
String char = "";
for( i = 0; i < characterArray.length; i++) {
char = char + characterArray[i]
} System.out.println(char);
Just typing hello gives me hello, but when I type hello world it does not type in the word "world".
View Replies
View Related
Jan 17, 2014
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);
[code]....
View Replies
View Related
Dec 14, 2014
I have to do a small program about parking. In the 2-d array (parking lot), contains different kinds of cars, the user have to :
1)enter which car he wanna move,
2)what direction (w,a,s,d) and after that,
3) how many moves( not out of bound) he wants to make, and finally
4) we print out the new parking lot for his next move
And i am stuck at how to move the car to corresponding position and then prompt user for the next move?
For example:
I want to move A to the right by 1 (d)
擷取.PNG
print result:
擷取1.PNG
How do I do that? The code that i have right now
public class CarParkGame {
public static void main( String [] args) {
String carPark[][] = new String [6][6] ;
carPark[0] = new String[] {"A","A","A","0","0","0"};
carPark[1] = new String[] {"b","0","0","0","0","c"};
carPark[2] = new String[] {"b","X","X","0","0","c","<exit>"};
[Code] .....
View Replies
View Related
Nov 15, 2014
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.
View Replies
View Related
Aug 6, 2014
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.
View Replies
View Related
Jul 8, 2014
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?
View Replies
View Related
Apr 13, 2014
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.*;
[code]....
View Replies
View Related
Mar 9, 2014
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:
// GUI-related imports
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Scanner;
// File-related imports
[code]....
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)
View Replies
View Related
Jun 22, 2014
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.
Here's what I have so far:
import java.nio.file.*;
import java.io.*;
import java.nio.channels.FileChannel;
import java.nio.ByteBuffer;
import static java.nio.file.StandardOpenOption.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
[code]....
View Replies
View Related
Feb 18, 2015
I am using the following code to create a dialog , but my need is user can select only 1 entry . Using this code
can select multiple items by pressing Ctrl ... How it can avoid ... My current code is
Java Code:
SecureCloudStorage_Service service = new SecureCloudStorage_Service();
List<String> files = service.getSecureCloudStoragePort().listFiles();
SelectFileDialog dialog = new SelectFileDialog(this.getFrame(),true,files);
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension screenSize = toolkit.getScreenSize();
int x = (screenSize.width - dialog.getWidth()) / 2;
int y = (screenSize.height - dialog.getHeight()) / 2;
dialog.setLocation(x, y);
dialog.setVisible(true); mh_sh_highlight_all('java');
View Replies
View Related
Feb 19, 2014
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.
View Replies
View Related
Mar 12, 2014
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.
View Replies
View Related
Nov 2, 2014
The LocalStudent class inherits the Student class. The IDE states an error of "no default constructor in Student class".I understand that if a LocalStudent object is created, the default constructor of its superclass (aka Student class) will be called implicitly.there is no LocalStudent object being created, so why is the default constructor of Student being called ?
The default constructor of LocalStudent is also overloaded by the created no-arg constructor containining subjects = null; . So there is no call to the superclass default constructor from the default constructor of LocalStudent.
public class Student {
private char year1;
public Student(String name, char year){
year1 = year;
}
public char getYear(){
return year1;
[code]...
View Replies
View Related
Mar 28, 2015
I am new in java. Is there any difference between protected or default when we are talking about one package?
View Replies
View Related
Feb 4, 2014
Will I'm tying in my code to set a default number for the JTextField that when the user decide not to put any numbers. Like let say that I want the textfield set to 0 , so then the user do not file it it won't make any problem to the program because its already has a default number.
if (stringGQ != null && stringGW != null && stringGP != null){
stringGQ = gMQ.getText();
stringGW = gMW.getText();
stringGP = gMP.getText();
weightPrice_1M = Double.parseDouble(stringGW) * Double.parseDouble(stringGP);
[Code] .....
Note: This is a small part of my code. when I leave it empty it take the 0 as a value, However, when I write in text field it also take the value of a 0 and the finalTotal is also = to 0.what I'm doing wrong.
View Replies
View Related