Skip to content
Snippets Groups Projects
Commit 6e7b33e4 authored by Goik Martin's avatar Goik Martin
Browse files

Replacing by maven project type

parent 6c8fceda
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
/bin
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Fraction1</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
package math;
public class Driver {
public static void main(String[] args) {
Fraction twoThird = new Fraction(2, 3), // Construct a fraction object (2/3)
threeSeven = new Fraction(3, 7); // Construct a fraction object (3/7)
Fraction sum = twoThird.add(threeSeven), // (2/3) + (3/7)
product = twoThird.mult(threeSeven); // (2/3) * (3/7)
System.out.println("(2/3) + (3/7) = (23/21) = " + sum.getValue());
System.out.println("(2/3) * (3/7) = (2/7) = " + product.getValue());
}
}
package math;
public class Fraction {
long numerator,denominator;
/**
* @param numerator The fraction's numerator.
* @param denominator The fraction's denominator.
*/
public Fraction(long numerator, long denominator) {
setNumerator(numerator);
setDenominator(denominator);
}
/**
* @return The fraction's decimal value e.g. 1/3 = 0.3333...
*/
public double getValue(){
return (double) numerator / denominator;
}
/**
* @return The fraction's numerator
*/
public long getNumerator() {
return numerator;
}
/**
* @param numerator Set the fraction's numerator.
*/
public void setNumerator(long numerator) {
this.numerator = numerator;
}
/**
* @return
* The fraction's denominator value
*/
public long getDenominator() {
return denominator;
}
/**
*
* @param denominator Set the fraction's denominator
*/
public void setDenominator(long denominator) {
this.denominator = denominator;
}
/**
* Add a second fraction to the current instance.
*
*
* @return The sum of the current instance and f according to:
*
<math display="block" xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<mrow>
<mfrac>
<mi>a</mi>
<mi>b</mi>
</mfrac>
<mo>+</mo>
<mfrac>
<mi>x</mi>
<mi>y</mi>
</mfrac>
</mrow>
<mo>=</mo>
<mfrac>
<mrow>
<mrow>
<mi>a</mi>
<mo>⁢</mo>
<mi>y</mi>
</mrow>
<mo>+</mo>
<mrow>
<mi>b</mi>
<mo>⁢</mo>
<mi>x</mi>
</mrow>
</mrow>
<mrow>
<mi>b</mi>
<mo>⁢</mo>
<mi>y</mi>
</mrow>
</mfrac>
</mrow>
</math>
*/
public Fraction add(Fraction f) {
return new Fraction( numerator * f.denominator + denominator * f.numerator,
denominator * f.denominator);
}
/**
* Multiply a second fraction by this instance
* @param f Building the product with this second fraction.
* @return The result of multiplying the current instance by f according to:
<math display="block" xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<mrow>
<mrow>
<mfrac>
<mi>a</mi>
<mi>b</mi>
</mfrac>
<mo>⁢</mo>
<mfrac>
<mi>x</mi>
<mi>y</mi>
</mfrac>
</mrow>
<mo>=</mo>
<mfrac>
<mrow>
<mi>a</mi>
<mo>⁢</mo>
<mi>x</mi>
</mrow>
<mrow>
<mi>b</mi>
<mo>⁢</mo>
<mi>y</mi>
</mrow>
</mfrac>
</mrow>
</mrow>
</math>
*/
public Fraction mult(Fraction f) {
return new Fraction(numerator * f.numerator,
denominator * f.denominator);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment