0% found this document useful (0 votes)
43 views4 pages

Programa: Triangulo Poo

The document describes a Java program that takes user input for the sides of a triangle (a, b, c), checks if the triangle is valid using a static method, calculates the perimeter and area if valid, and prints the results. The main class creates a Triangle object, calls its input, validation and output methods. The Triangle class has fields to store side lengths and results, input methods to read each side, and methods to validate, calculate perimeter/area, and print outputs.

Uploaded by

Sebas Santin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views4 pages

Programa: Triangulo Poo

The document describes a Java program that takes user input for the sides of a triangle (a, b, c), checks if the triangle is valid using a static method, calculates the perimeter and area if valid, and prints the results. The main class creates a Triangle object, calls its input, validation and output methods. The Triangle class has fields to store side lengths and results, input methods to read each side, and methods to validate, calculate perimeter/area, and print outputs.

Uploaded by

Sebas Santin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

PROGRAMA: TRIANGULO POO

package Paquete;

/**
*
* @author eto-g
*/
public class Programa {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here

Triangulo ObjTriangulo = new Triangulo();

ObjTriangulo.LeerDatos();
ObjTriangulo.verificar();

//ObjTriangulo.PerimetroRectangulo();
//ObjTriangulo.AreaRectangulo();
//ObjTriangulo.ImprimirDatos();
}

}
package Paquete;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
*
* @author eto-g
*/
public class Triangulo {

private float mA, mB, mC, mPerimetro, mArea, mS;

public Triangulo()
{
mA = 0.0f; mB = 0.0f; mC = 0.0f;
mPerimetro = 0.0f; mArea = 0.0f;

public void LeerDatos()


{
String sDato= "";
float a;
try
{
System.out.printf("Ingrese el valor del lado 'a': ");
InputStreamReader ObjISR = new InputStreamReader(System.in);
BufferedReader ObjBR = new BufferedReader(ObjISR);
sDato = ObjBR.readLine();
mA = Float.parseFloat(sDato);

}
catch(IOException e)
{
System.err.println("Error: "+ e.getMessage());
}

float b;
try
{
System.out.printf("Ingrese el valor del lado 'b': ");
InputStreamReader ObjISR = new InputStreamReader(System.in);
BufferedReader ObjBR = new BufferedReader(ObjISR);
sDato = ObjBR.readLine();
mB = Float.parseFloat(sDato);

}
catch(IOException e)
{
System.err.println("Error: "+ e.getMessage());
}

float c;
try
{
System.out.printf("Ingrese el valor del lado 'c': ");
InputStreamReader ObjISR = new InputStreamReader(System.in);
BufferedReader ObjBR = new BufferedReader(ObjISR);
sDato = ObjBR.readLine();
mC = Float.parseFloat(sDato);

}
catch(IOException e)
{
System.err.println("Error: "+ e.getMessage());
}
}

public void ImprimirDatos()


{
System.out.printf("Perimetro: %f\n", mPerimetro);
System.out.printf("Area: %f\n", mArea);
}
public static float SemiperimetroTriangulo(float a, float b, float c)
{
return((a+b+c) / 2.0f);
}
public void PerimetroRectangulo()
{
mPerimetro = mA + mB + mC;
}
public void AreaRectangulo()
{
mS = SemiperimetroTriangulo(mA, mB, mC);
mArea = (float)Math.sqrt(mS*(mS-mA)*(mS-mB)*(mS-mC));
}
public static boolean VerificarTriangulo(float a, float b, float c)
{
if((a+b > c) && (a+c > b) && (b+c > a))
{
return(true);
}
else //((a+b > c) && (a+c > b) && (b+c > a));
{
return(false);
}
}

public void verificar()


{
boolean verificar;
verificar = VerificarTriangulo(mA, mB, mC);
if(verificar == true)
{
PerimetroRectangulo();
AreaRectangulo();
ImprimirDatos();
}
else
{
System.out.printf("Error... el triangulo no existe\n");
}
}

}
Captura de
corrida:

You might also like