I was wondering how you would change a double to a fraction.
For Example:
double x = .5
From this we know that the fraction is obviously 1/2 (simple form of course), but what are the steps necessary to convert the double to the fraction 1/2?
For some reason, I'm getting the correct result, but my negative sign is having issues. For example, if I do 1/4 - (-2/4), I get (-3/4).
Here is my minus method for subtracting fractions.
/** Subtracts a fraction from another fraction. @param toUse, the fraction to subtract. @return minusFraction, the result after subtraction. */ public Fraction minus(Fraction toUse)
[Code] .....
Here is my reduce() method, just in case...
/** Reduces the fraction, if possible, to it's simplest form. Converts negative fractions to the form -x/y, or if -x/-y --> x/y */ private void reduce() { int lowest = Math.abs(numerator); int highest = Math.abs(denominator);
[code]...
I only switched an operator from my previous addition method, given here as well. I think only switching the + to a - may have caused my issue.
/** Adds two fractions together. @param toUse, the fraction to be added. @return plusFraction, the sum of the two fractions. */ public Fraction plus(Fraction toUse) {
I am trying to get the average of 3 different fraction arrays. I made a fraction class and I made methods such as read() and average() in this new class.
package fractions; import java.util.Scanner; import java.util.Arrays; public class FractionArrays { public static void main(String[] args) { Fraction completeFraction = new Fraction(5,6);
[Code] ....
I was wondering if there was any way to use the arrays I created in the read method in the average method. If I find that out I should be able to do it on my own. Is there a way to make the arrays public to use in different methods?
I am supposed to make a code which can handle fractions as a calculator in the form of 1_1/2 + 1 = 2_1/2
This is what I've done so far and now im just lost.
Heres my code:
import java.util.Scanner; import java.util.StringTokenizer; public class FracCalc { public static void main(String[] args ){ // read in the first expression
package FracCalc; import java.util.Scanner; public class FracCalc { public static void main(String[] args) { Scanner scan = new Scanner(System.in);
int n1 = 0; //n1 = first numerator user have to enter int d1 = 0; //d1 = first denominator user have to enter int n2 = 0; //n2 = second numerator user have to enter int d2 = 0; //d2 = second denominator user have to enter int numeratorAnswer = 0; //calculates numerator of an equation int denominatorAnswer = 0; //calculates denominator of an equation
[code]...
I mean its not that important but i figure it will be better if I could print out the answer both in fraction format and decimal format. while my answer prints in fraction just fine how do i show it in decimal?
System.out.println("");
System.out.print("And "); System.out.print("answer in Decimal is: ");
So all the errors in the code is fixed but its now got the wrong output
what I get:
Enter numerator; then denominator. 5 8 5/8 Enter numerator; then denominator. 4 10 4/10 Sum:0/0
it should be:
Enter numerator; then denominator. 5 8 5/8 Enter numerator; then denominator. 4 10 4/10 Sum: 82/80 1.025 Product: 20/80 0.25 Enter numerator; then denominator. 6 0 infinity
here is the code
Fraction.java public class Fraction { //declares that it's a class that can be intantiated private int numer; // private intager for numerator private int denom; // private intager for denominator
I've been writing a fraction class code below that does a number of arithmetic calcs and when I run it these are the results I get. My gcd doesn't work when it comes to negative fractions and I'm not quite sure how to print.out the boolean methods ((greaterthan)), ((equals))and ((negative)). I'm also not sure if I have implemented those 3 methods properly. I'm still learning how to do unit testing.
Enter numerator; then denominator. -5 10 -5/10 Enter numerator; then denominator. 3 9 1/3 Sum: -5/30 -0.16666666666666666 Product: -5/30 -0.16666666666666666 Devide: -15/30 -0.5 subtract: -45/90 -0.5 negative: 1/6 0.16666666666666666 Lessthan: 1/6 0.16666666666666666 greaterthan: 1/6 0.16666666666666666
FRACTION CLASS
import java.util.Scanner; public class Fraction { private int numerator; //numerator private int denominator; //denominator
We're learning how to use Binary I/O commands...which equates to....
My issue is trying to relate the Fraction objects (which we are to create using a loop) with the read/write methods used in Binary I/O (input/output streams). I left a blank after the output.write(), so you can see where the issue exist.
Java Code:
import java.io.*; public class FractionTest { public static void main(String[] args) { int [] fraction = new int[3]; for(int i = 0; i <= fraction.length; i++){ Fraction numbers = new Fraction();
I am currently working on Java software which resize jpeg images and change DPI also. For JPEG images having app0JFIF node it works fine and the images new DPI is reflected in Photoshop. But if app0JFIF node not exist, I am trying to create a new one and set the DPI value there. Everything is going proper but if I open these images in photoshop it does not reflect new DPI but the size changes.
My understanding was I could override a method from the superclass, including with different parameters, but when I try to use super. it gives me an error the arguments have to match the superclass. But, if I do that it won't make any sense.
The first code below is the superclass. The issue I'm having is on the second code at lines 7 and 10. The ultimate goal is to make a new class where I'm able to display various packages with or without insurance.
public class Package { double shippingWeight; public char shippingMethod; final char air = 'A'; final char truck = 'T'; final char mail = 'M'; double shippingCost;
I am having trouble doing a simple exercise changing a for loop to a while statement, it works fine in the for loop but in the while statement it just prints out 10(it is supposed to count to 0 and print liftoff).
public void run() { int i = 10; while (i>=1) { println(+i+"..."); i--; } println("liftoff..."); }
I'd like to make a simple cheat for an old game that's offline... It has no type of anti-cheat and I'd like to make a program that changes how much money you have... I think the first thing I have to do is get the data address or something like that by using cheat engine... How do I do that? After that how do I start using that info in my program and then send back a new value? Are there any classes that I should be importing and what methods do I use to do this?
currently the timer works its format is in 00:00 minutes:seconds, but i want it to start as MMMM d, yyyy h:mm:ss, for example March 17 2014 00:00:01, so only one second has passed here. i believe the set and get format method is fine but the timerhaschanged needs to change as this is where the format takes place.
I am making a simple text based game and i have a monster, and I am tring to make its health go down whent he user input "s" but istead it doesnt change and the users health even goes up.
Main.java
package exodus.game.main; import java.util.Scanner; import exodus.game.monsters.Nirav; public class Main { static String name; static String inputtemp;
Every time I load a txt file into a JTextArea it prints the results to the JFrame incorrectly I notice its mainly the white spaces this is happening to. I have tried a few ways to remedy this problem but it still keeps occurring? I've tried append() read() also setText() even Scanner. I have enclosed a picture of my GUI and my txt file I am using.
The Toys of the Future Company has decided to issue a new line of toy robots. While they are not sure exactly what their robots will look like, they do know the functionality that they will all have. All robots will be able to move forward, turn right, turn left, spin and detect an object in front of it via a sensor. The robot will use a touch sensor to determine whether it has hit an object in front of it, such as a wall. The robot will have two, three, or four wheels, but it will only be driven by two of them: a right wheel and a left wheel. Each wheel will be attached to a motor that controls it.
* ^ this is only something to think about Produce a UML class diagram.
Using UML, describe the objects and classes that will be associated with this new toy. Either hand draw or use an appropriate UML creation tool to generate a UML design document for your Robot class. Create a set of classes that can be used to control the robot.
Develop your new class.
Create a new NetBeans project entitled, "Assignment_8_1" and develop your new class. Now, using the objects and classes that you have written, write a program for your robot that allows it to move in a large square. Allow your robot to run in a big two dimensional array and every time the robot encounters a square in your array, turn that square black.
So here is the code for the moving ball:
package ballapplet; import java.awt.*; import java.util.Formatter; import javax.swing.*; public class BallApplet extends JPanel { private static final int BOX_WIDTH = 640;
[Code] ....
I want to know how to change the color of an object, and how to move it in specific directions.
I'm having some trouble figuring out how to change the value of a variable that is passed into a class. I've tried just changing the variable, I've tried changing it by using the this.variable command, and I've even tried calling the setter class from within the class to change it, but it's still not working right. The first class is the one with Main in it and I just feed it some dummy data:
public class ExamConverter { public static void main(String[] args) { // TODO Auto-generated method stub Age testAge = new Age();
[Code] .....
This is the other class to calculate the age the way we do it on psych tests - it might not be mathematically accurate, but it's what all the tables and such for raw to scaled score conversion are based on, so the math needs to be the same as opposed to "accurate" because of some months having 30 or 31 days, etc.
public class Age { //==================Properties================== // Variables for the test date and client date of birth private int TestMonth; private int TestDay; private int TestYear; private int ClientMonth; private int ClientDay; private int ClientYear;
[Code] ......
Based on this dummy data, the output is: Test: 5/4/2014 DOB: 5/5/1971 Age Years: 43 Months: 0 Days: 0
However, it should be: Test: 5/4/2014 DOB: 5/5/1971 Age Years: 42 Months: 11 Days: 29
I have a empty JList in which I hit a button LOAD DATA which should load all the data. but once I load data i try to fill in the List but I keep getting errors.
String[] aos = new String[itrList.size()]; itrList.toArray(aos); //JList listFAIL = new JList(aos); //list = new JList(itrList.toArray()); //list.removeAll(); list.setListData(aos); JScrollPane s = new JScrollPane(list);
I am starting to learn java , If suppose we write a simple hello world program
class helloWorld { public static void main(String args[]) { System.out.print("Hello World !"); } }
And save this as test.java.Now after compiling it a helloWorld.class file is generated.But if we compile the same after adding "public" in front of 1st line, it throws error.
public class helloWorld { public static void main(String args[]) { System.out.print("Hello World !"); } }
but then changing the file name to the name of the class i.e. helloWorld.java, corrects the error.
I have been working on a program that is meant to use a class' instructions in a program to add a value to a variable, save it, and present it. This is my class
public class Car { //FIELDS private int yearModel; private String make; private int speed; //METHODS public Car(int carYearModel, String carMake)
[Code] .....
Whenever I call the accelerate method, a value of 5 is to be added to the speed variable. But whenever I call accelerate, it doesn't increase! I just don't understand why not. I've tried different renditions of adding 5 to speed and it doesn't quite work. I don't get any errors when I compile, just runtime, when it doesn't add 5 to speed.
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've created a method named parseStringToDate this method takes a string parameter and parse it to the date: here is my code:
public Date parseStringToDate(String date) throws ParseException{ DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.SHORT, Locale.getDefault()); return formatter.parse(date); }
i'm trying to parse a String to date then:
public static void main(String args[]) { MyDate a = new MyDate(); try { Date d = a.parseStringToDate("Wednesday, August 13, 2014 3:33 PM"); System.out.println(d); } catch (ParseException e) { e.printStackTrace(); } }
As i've defined DateFormat in the method, now i'm passing it a date accordingly: "Wednesday, August 13, 2014 3:33 PM" And the output is: Wed Aug 13 15:33:00 PKT 2014
Which is not equal to the format i gave it.. how can i change its format to same as i've given input. InShort i want to parse a string to date and it should convert that String to date with exactly the same format.