Created
March 25, 2019 20:27
-
-
Save danicunhac/9ccd47232b6432487f08721f95c44b19 to your computer and use it in GitHub Desktop.
Fração
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Aplicacao { | |
public static void main(String[] args) { | |
Fracao f1 = new Fracao(); | |
f1.definirValores(7, 3); | |
Fracao f2 = new Fracao(); | |
f2.definirValores(3, 2); | |
Fracao f3 = f1.multiplicar(f2); | |
System.out.println(f3.obterFracao()); | |
System.out.println(f3.calcularValor()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Fracao { | |
double numerador; | |
double denominador; | |
void definirValores(double numerador, double denominador) { | |
this.numerador = numerador; | |
this.denominador = denominador; | |
} | |
double calcularValor() { | |
if(denominador == 0) { | |
return 0; | |
} | |
return numerador/denominador; | |
} | |
Fracao multiplicar(Fracao f) { | |
Fracao result = new Fracao(); | |
result.numerador = this.numerador * f.numerador; | |
result.denominador = this.denominador * f.denominador; | |
return result; | |
} | |
String obterFracao() { | |
return numerador + "/" + denominador; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment