This program deals with a variation of the geographic coordinate system with Greenwich at 51° 28' 38" N. The program will be adding the three values of one coordinate to the three values of the second coordinate. Though the maximum value for seconds and minutes is 59, the user can enter values greater than that number when prompted. The maximum degree is 360 for this assignment though the user can enter values greater than that number.
I have quite a specific view for how I want my components layed out. No matter what I try I can get them to display how I want! I'm using three JPanels. There's a main panel that goes inside the tabbed pane. This main panel contains two other panels. The First panel is a gridbaglayout panel, with labels on the left column, and components on the right column. The second panel is underneath the second, and contains a label, and a button beneath it. THis uses a basic box layout, with one component per line. The label doesn't always appear (depends if a component is changed). With everything showing, this is how it looks so far:
However, I want the Labels on the left of the pane. The right hand column should be aligned horizontally and have more space from the labels. Ideally I'd like a gap between the last label/checkbox and the Note label.
This is my current code for the panel/s inside the tabbed pane window.
videoPanel = new JPanel(); applyVidBtn = new JButton("Apply Settings"); applyVidBtn.setVisible(false); warningLbl = new JLabel("Note. Applying these settings causes a program restart."); warningLbl.setVisible(false);
Why this extremely simple program seems to be giving me a negative value for amount of calculations done within one minute ( Just using it as a bit of fun to see how different computers in the office perform).
Java Code:
class Benchmark { public static void main(String[] args) { long endTime = System.currentTimeMillis() + 60000; int count = 0; for (int i = 0; System.currentTimeMillis() < endTime; i++) { double x = Math.sqrt(System.currentTimeMillis()); count = i; } System.out.print(count + " calculations per minute"); } } mh_sh_highlight_all('java');
I am getting results between -2.1billion and -3.4billion which to me would make sense since they are not the best computers in the world but I would be expecting a positive value?
So I have re-written the code but it is still not running correctly. Any number i type in it throws an exception, also i need the program to add the totals that i type in and then once i type -1 into the prompt button list all the number i typed in and give me the average.
import java.awt.*; import java.awt.event.*; import javax.swing .*; import javax.swing.text.*; public class Averages extends JFrame { //construct components JLabel sortPrompt = new JLabel("Sort By:");
I do now have the problem where i have to insert the numbers 1 to 100 individually in order to allow the program to accept a grade as high as 100%.
Also as soon as i type in a negative number the system crashes and shows me a error as attached.
/* Averaging grades To use the Java Swing interface to calculate the average of up to 50 grades.Average is calculated once -1 is entered as a value. The grades are then sorted from lowest to highest and displayed in a content pane which also displays the average. */
import java.awt.*; import java.awt.event.*; import javax.swing .*; import javax.swing.text.*; public class Averages extends JFrame { //construct components JLabel sortPrompt = new JLabel("Sort By:");
Ok so I have my program working for the most part. In this program I am supposed to take input from the user until they enter a negative number and that works, the problem is that it doesn't work if I enter a negative number on the first prompt. For example if I enter a 100 it would prompt me again and if I enter a negative number it would quit and give me the average, but if I enter a negative number the first time I am prompted the program just gives me an error. How do I fix that?
import java.util.List; import java.util.ArrayList; import java.util.Scanner; public class Application { public static void main(String [] args){ Scanner input = new Scanner(System.in); List<Integer> grades;
In my cs class, we have to write a program that throws an exception if the user enters a negative number, the program should prompt the user to enter only positive numbers and then let them retype the number. But everytime I throw an exception, my program gets suspended.
What am I doing wrong, or is there no way to continue a program if an exception is thrown? Does the program automatically get suspended when an exception is thrown?
try{ do { N = kb.nextDouble(); if(N<0) { throw new NegativeArraySizeException(); } else j++; } while(j==0); fill.size(N); } catch(NegativeArraySizeException e) { System.out.println("The number you entered must be positive. Please try again."); }
I have a set of 2D arrays, structured as so: int[][] cage = new int[someLength][4]. Each array has a set column length of 4; the first two columns are all that concern us with this problem. They are used to define the row and height respectively of a point (e.g. 2,4).
What I need is to generate all possible permutations of the points using both row and column coordinates from the 2D array. I found a working method to generate all permutations for 1D array of ints here: [URL] ..... , under update 2 of the first answer.
Here is an example of a possible input and corresponding output desired:
In: (1,0) (1,1)
Out:(1,0),(1,1) (1,1),(1,0)
Ideally the result will be stored in a 2D array of ints.
I have a set of 2D arrays, structured as so: int[][] cage = new int[someLength][4]. Each array has a set column length of 4; the first two columns are all that concern us with this problem. They are used to define the row and height respectively of a point (e.g. 2,4).
What I need is to generate all possible permutations of the points using both row and column coordinates from the 2D array. I found a working method to generate all permutations for 1D array of ints here: My link, under update 2 of the first answer.
Here is an example of a possible input and corresponding output desired:
I've been pondering about this algorithm for about a week but I'm still not able to write a "fast" working method/algorithm to solve the Number-of-paths-exercise we were given in my class />
So here's the task: Write an efficient java program "Paths" which solves the following task:
- Read input n ∈ N and give output a(n) which is the number of paths from (0,0) to (n,0) it is not allowed to go over the diagonal (m,m) and also not below the x-axis (m,0)
Here are the allowed steps: u = (1,1), U = (1,4), d = (1,−1), D = (1,−4) and H = (1,0) steps are performed in a two-dimensional-coordinate-system!
Ok Im trying to create a code right now that will take a table of rectangular coordinates and convert them to Polar coordinates in the constructor. I will eventually calculate the total distance between all points in the calculateDistancePolar method but for now I am using it to test.
It doesnt like line 29 and 31 of the class Polar and I cannot figure out why.
public class Test { public static void main(String[] args) { double[][] coords = {{86.92, 2.47},{70.93, 27.81},{97.74, 34.36},{30.90, 35.14},{51.66, 31.70},{0.830, 21.77},{55.91, 66.62},{32.92, 75.23},{65.26, 72.53},{83.90, 4.710}}; System.out.println("X,Y Coordinates are:"); outputArray(coords); Polar myTest = new Polar(coords);
I'm having a random x and y coordinate generate and I need to check if the coordinates are inside of a right triangle on this imaginary coordinate plane.
But the error is giving me incompatible types. I would like to set all the pixels at a certain point up to the dimensions of my rectangle and so on. How would I do that?
Using the concept of web service (SOAP), I need to have a web service running. The client page will pass an ID to the web service and in return the service will return some values retrieved from the database based on the ID passed, as output. The output so fetched has to be in XML format.
I'm making a Hangman program for Java, here's my code:
import java.util.Scanner; public class Hangman { /** * @param args the command line arguments */ public static void main(String[] args) { String answerWord = WordList.getWord();
[Code] .....
The Compiler gives me this only error:
Hangman.java:39: error: unexpected type displayWord.charAt(i)=userInput.charAt(0); ^ required: variable found: value
I understand that charAt returns i as a value and not a variable. What do I use to return a variable as I intended?
I want to use a switch or if/else statement to filter out the data I don't need for the app. This is by no means anything more than a draft because java is easier to work with than android.
I developed an application that is accessing some property files. The condition was that the user should be able to modify the content or parameters of those property file.How can I distribute the application using Java web start that also includes those property file in the client side?
This program simply adds integers to an ArrayList and then prompt the user if they would like to delete specific numbers that they don't want.
The output that I get when I want to delete numbers like 2 and 4 from 1 2 3 4 5 is 1 2 3 4 5 instead of 1 3 5.
Java Code:
import java.util.ArrayList; import java.util.Scanner; public class AL { // A regular array like int arr[] has to have its size declare before run-time and it's not dynamic which mean it can not grow or expand on its own. static Scanner input = new Scanner(System.in); // You have to use reference types(Integer, Double, Float); not primitive types(int).
We currently have an application which uses JDBC to connect to the backend database (DB version - 11.2.0.3 ). The application uses a properties file in which the password for the db schema is hardcoded in plain text format. Due to security restrictions we have been asked to make sure the password is encrypted in the file and no direct access is made to the schema using the plain text password. Best options we can use to make this password encrypted both at Oracle DB side and Java side.
when i input a positive integer it works but when i input a negative number it doesn't work
my pseudo code:
READ input WHILE( NOT CORRECT INPUT) READ INPUT AGAIN; ENDWHILE DECLARE array arr[input] FOR(i=0 to input-1) arr[i]= Random number from 0 to 100; ENDFOR DISPLAY ARRAY
error message when i input -5 : Exception in thread "main" java.lang.NegativeArraySizeException atPosNeg.main<PosNeg.java:36>
import java.util.*; class PosNeg{ public static void main(String args[]) { Random generator = new Random(); Scanner scan = new Scanner(System.in);