Commit 5eec23ef by Cristian Caceres

inicial proyect

parents
<?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>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>calculadora</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 calculadora;
import jdk.internal.org.objectweb.asm.tree.TryCatchBlockNode;
/**
* @author crist
*
*/
public class Calculadora {
float a;
float b;
public Calculadora(float a, float b) {
this.a = a;
this.b = b;
}
public float getA() {
return a;
}
public void setA(float a) {
this.a = a;
}
public float getB() {
return b;
}
public void setB(float b) {
this.b = b;
}
public float suma() {
try {
return this.a+this.b;
} catch (Exception e) {
// TODO: handle exception
System.out.println(e);
}
return 0;
}
public float resta () {
try {
return this.a-this.b;
} catch (Exception e) {
// TODO: handle exception
System.out.println(e);
}
return 0;
}
public float multiplicacion() {
try {
return this.a*this.b;
} catch (Exception e) {
// TODO: handle exception
System.out.println(e);
}
return 0;
}
public float division() {
try {
return this.a/this.b;
} catch (Exception e) {
// TODO: handle exception
System.out.println(e);
}
return 0;
}
public float mod() {
try {
return (this.a%this.b);
} catch (Exception e) {
// TODO: handle exception
System.out.println(e);
}
return 0;
}
public boolean esPrimoA() {
if(esPrimo(this.a)) {
return true;
}else {
return false;
}
}
public boolean esPrimoB() {
if(esPrimo(this.b)) {
return true;
}else {
return false;
}
}
public static boolean esPrimo(float numero) {
if(numero==0) {
return false;
}
if(numero==1) {
return true;
}
for (int i = 2; i < numero; i++) {
if(numero%i==0) {
return false;
}
}
return true;
}
}
/**
*
*/
package calculadora;
import java.util.Scanner;
/**
* @author crist
*
*/
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
boolean bandera= false;
Scanner scan = new Scanner(System.in);
float numero1=0;
float numero2=0;
System.out.println("Ingrese dos nmeros");
System.out.println("Numero 1:");
while(!bandera) {
try {
numero1= scan.nextFloat();
bandera=true;
} catch (Exception e) {
// TODO: handle exception
System.out.println("Ingrese de nuevo numero 1: ");
}
}
System.out.println("Numero 2:");
while(bandera) {
try {
numero2= scan.nextFloat();
bandera=false;
} catch (Exception e) {
// TODO: handle exception
System.out.println("Ingrese de nuevo numero 2: ");
}
}
System.out.println("numero1 vale: "+ numero1);
System.out.println("numero1 vale: "+ numero2);
Calculadora cal = new Calculadora(numero1,numero2);
System.out.println("la suma de numero1 + numero2 es: "+cal.suma());
System.out.println("la resta de numero1 - numero2 es: "+cal.resta());
System.out.println("la multiplicacion de numero1 * numero2 es: "+cal.multiplicacion());
System.out.println("la division de numero1 / numero2 es: "+cal.division());
System.out.println("el mod de numero1 & numero2 es: "+cal.mod());
System.out.println("el numero 1 es primo?: "+ cal.esPrimoA());
System.out.println("el numero 2 es primo?: "+ cal.esPrimoB());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment