Ok, so in my quest to achive perfect ray casting and line/plane intersection, what I believe to be my last problem is precision of a float. I need some precision (0.000) but I am dealing with the difference of (-1.000000000) and (-1.000000002), where the second number would be completely off. I looked at DecimalFormat, but that just puts it into a string, I need actual loss of precision.
Java Code:
DecimalFormat form = new DecimalFormat("0.00");
String newX = form.format(x);
String newY = form.format(y);
String newZ = form.format(z);
x = Float.parseFloat(newX);
y = Float.parseFloat(newY);
z = Float.parseFloat(newZ); mh_sh_highlight_all('java');
I'm stuck trying to figure out why this isn't compiling.
Bumper.java:87: error: possible loss of precision myX = (Math.random()* (rightEdge-myXWidth) + myXWidth / 2); ^ required: int found: double Bumper.java:88: error: possible loss of precision myY = (Math.random()* (bottomEdge-myYWidth) + myYWidth / 2); ^ required: int found: double
I have run into a bit of a head scratcher, at least to me. I am building multiple rectangles using double precision. I had to switch from int to double due to another issue that requires decimal places. Now, my fillRect (last line in the code section I posted) is causing an error as it only wants to work with int.
public void draw(Graphics2D g2) { // check that sizes are above 0 if ((rectWidth <= 0) || (rectHeight <= 0))
I am teaching myself Java and am trying to write a function that will determine all of the perfect squares between 1 and 100 but am running into a problem...
Here's my code:
package sqrroot;
public class SqrRoot { /** * @param args the command line arguments */ public static void main(String[] args) { double sroot, rerr; int count = 0; for(double num = 1.0; num <= 100.0; num++){
[Code] ....
and here is the output:
run: 0.0 1.0 is a perfect square. 0.0 4.0 is a perfect square.
[Code] ....
There are 49 perfect squares between 1 and 100. BUILD SUCCESSFUL (total time: 6 seconds)
Which is clearly wrong. Is there something wrong with my code or is this due to inherent imprecision in the double type or the Math.sqrt function?
I have code for precision and recall testing for search engines. I am trying to run it in Newbeans 8.0, but I am getting the common error in UnsupportedOperationException
I have tried making files and directories as the given in the code file. I am attaching the two files here.
I was asked to write code to calculate a person's calories burned/min. This is what I got. The problem is I keep getting an error.
--------------------Configuration: <Default>-------------------- C:Program FilesJavajdk1.7.0_72CaloriesBurned.java:22: error: possible loss of precision caloriesBurnedPerMinute = 0.0175 * METS * weightInKg; ^ required: int found: double 1 error
Loss of precision? What does that mean? Do I have to change weightInKg into some other number type?
import java.util.Scanner; public class CaloriesBurned { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); int runningHours, basketballHours, sleepingHours, METS, caloriesBurnedPerMinute;
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.
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.
I am getting the blank value in the array and this code is passed in IVR for playing the values since the first value is blank the prompts arrangements is disturbed. I want to replace the blank space or value by zero.
How do I write a program that shows the max and the min value of a float integer? like for example in order to get the max value of a long integer we type System.out.println(Integer.MAX_VALUE); How would I do that for a float integer?
Doing an early exercise out of the Java Examples in a Nutshell book and they are asking for 'an efficient search algorithm to find the desired position' of two floats in a sorted array that bound an int. My try is below:
public static int search(int searchnum, float[] nums){ int low = 0; int high = nums.length - 1; int mid = (low + high) / 2; while(low < high){ if(nums[mid] < searchnum){
[Code] ....
This is working for the example but I would like to know if it is considered 'efficient' or even good?
I am trying to write a Float Array to a file but it is only writing the last line of the array to a file. I have also attached the entire assignment as a zip file with all required files. Here is the part of the code I am having issues with:
I'm having extreme difficulty in working with a Vector storing a column with a BigDecimal value, and converting that single value into a float. I'm not sure why the code was written this way, but basically, I'm working with something called a vector that has a single Big Decimal value/column (not sure what the correct terminology is), and I want to store that value in a float variable called "dp". However, I don't know how to convert from the Big Decimal to a float.
Code is below:
String s = ""; sql = "SELECT DiscountPercentRate FROM Attendees WHERE AttendeeId=" + attendeeId; Vector v2 = sqldb.getResults(sql); /*I know that sqldb.getResults(sql) returns a vector with a single BigDecimal column of 15.0, in the test example I'm using*/ if (!v2.isEmpty()) { Vector data2 = (Vector)v2.elementAt(0); if (!data2.isEmpty())
[Code] .....
In case you're wondering what the sqldb.getResults() method looks, like, here's a snippet of it - There's an else statement that triggers in my case, adding a BigDecimal column to a vector, and returns that vector.
Vector v = new Vector(); ... else { BigDecimal bd = rs.getBigDecimal(i); vCols.add(bd); } v.add(vCols); ... return v;
How can I take the single result of my SQL query in that Vector/Big Decimal thing, and turn that result into a float value?
I am currently learning about JOption pane. Using Strings I am accepting an input from the user and by using the Interer.ParseInt(variable) option I am able to multiply this two strings using the code below.
String Length; Length = JOptionPane.showInputDialog("Enter the Length"); String Breadth; Breadth = JOptionPane.showInputDialog("Enter the Breadth"); System.out.println(" Area is " + (Integer.parseInt(Breadth) * Integer.parseInt(Length))); System.exit(0);
Now My question is... How Do I make my code accept Decimal values. E.g. My Code should accept 10.02 as Length and 20.42 as Breadth and give the product a Decimal. How Do I do this???
While doing trial and error got caught in the below scenario.
public class Crypt { public static void main (String args[]) { /*all I want is calculate a binary number (ex -: 22 , 34) using decimal base (10n). *So, I have to convert 2 p into 10n form so I have to find n in terms of p . We have x as the input. * The formula works as below. *2p =10n *p ln (2) =n ln (10) *n = p [ln(2) / ln(10)] *2 p = 10 p [ln(2) / ln(10)]
I've recently came into reading that term big decimal, but I still don't fully understand what the benefit it is or why wouldn't you just use double and say have the program stop after a certain range?
I created this program to display a square root table. Problem is all of my output is too long. I would like to round the number to 4 spaces past the decimal. Here is my code:
I have a case where I want to float a modeless popup on top of all other content. Seems like a Popup is ideal for this. Except for the following annoyances:
I don't see any way to tie its position to some owner window. You can supply an initial anchor position, but I noticed that if I drag the frame of the app window containing the JavaFX application, the Popup remains where it is and can actually appear outside the bounds of the App! I find this very disconcerting. I suppose I could bind its position to the screen coords of the Stage, but it would seem that I should not have to do this.If I minimize the app, the Popup remains visible. Rather odd given that when I called Popup.show(Window), you would think when the owner Window got hidden it would hide the owned Popups too. Again, I could probably bind to some property on the Stage, but like (1), it seems you should not have to do this.
I haven't tried this while embedding the Scene in a browser. I certainly hope that these Popups should not be allowed outside the bounds of the browser window. That spells trouble.
I'm supposed to write a program, which reads float numbers from a file, puts them in an array and sorts the array. After that I'm suppose to add the numbers so that when I add the 1 and 2 number of the array, I'm suppose to save the sum on the position of number 1, then I add number 3 and 4 and save the sum on position 2 etc. Also if my array has an uneven number of floats it's suppose to add the last 3 and not 2 numbers in the last iteration. The problem is the method throws an ArrayOutOfBounds Exception but I can't seem to find my mistake.
That's the second method. The first one just stores the sum in another variable and then returns it. Also is there a way in that I can Scanner/File/array etc. and initialize the array only once so I don't write the same code two times like it is now.
package sumOfFloats;
import java.io.File; import java.io.FileNotFoundException; import java.util.Arrays; import java.util.Scanner; public class SumOfFloats { public static float sumFloats() throws FileNotFoundException{