Sie sind auf Seite 1von 9

INSTITUTO TECNOLÓGICO DE MATEHUALA

PROGRAMAS
Elaboró:
Barbosa rodríguez Pedro Alberto
Castillo Hernández Ángel Arturo
Conde Olivares Juan Armando
Sauceda Olvera Juan José
López García Francisco Rubén

Materia: Algoritmos y lenguajes de Programación


Docente: Ing. Martín Luis Ledezma Hernández
Carrera: Ingeniería Industrial
Grupo: Cuarto semestre “A”
Unidad 4: Funciones
Semestre: Enero-Junio 2011

Matehuala, S.L.P. Mayo 2011


Problema #1 Convertir una temperatura dada en grados Fahrenheit a grados centígrados.

PROGRAMA

// Ejercicio: Conversion.java
// Convertir grados Farenheit a grados Celsius.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Conversion extends JApplet implements ActionListener {
JLabel promptLabel;
JTextField inputField;
// create GUI
public void init()
{
Container container = getContentPane();
container.setLayout( new FlowLayout() );
promptLabel = new JLabel( "Escribir los grados Farenheit:" );
inputField = new JTextField( 10 );
inputField.addActionListener( this );
container.add( promptLabel );
container.add( inputField );
} // end method init
// Convertir grados Farenheit a grados Celsius
public void actionPerformed( ActionEvent actionEvent )
{
double gradosFarenheit =
Double.parseDouble( actionEvent.getActionCommand() );
double gradosCelsius =
Double.parseDouble( actionEvent.getActionCommand() );
showStatus( " Los grados Celsius son " + gradosCelsius( gradosFarenheit ) );
} // end method actionPerformed
// Convertir y regresar a grados
public double gradosCelsius( double gradosFarenheit )
{
double Celsius = (gradosFarenheit - 32)/1.8;
return Celsius;
} // fin del metodo gradosCelsius
} // fin de la clase Conversion
RESULTADOS DEL PROGRAMA
Problema #2 Calcular el diámetro, circunferencia y área de un círculo en base a su
radio que es un número entero.

PROGRAMA
// Ejercicio: Area.java
// Calcular el area de un circulo.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Area extends JApplet implements ActionListener {
JLabel promptLabel;
JTextField inputField;
// create GUI
public void init()
{
Container container = getContentPane();
container.setLayout( new FlowLayout() );
promptLabel = new JLabel( "Escribir el radio:" );
inputField = new JTextField( 10 );
inputField.addActionListener( this );
container.add( promptLabel );
container.add( inputField );
} // end method init
// calcular el area de un circulo
public void actionPerformed( ActionEvent actionEvent )
{
double radio =
Double.parseDouble( actionEvent.getActionCommand() );
showStatus( " El diámetro es " + diametrodelcirculo( radio ) + " El área es " +
areadelcirculo( radio )
+ " La circunferencia es " + circunferenciadelcirculo ( radio) );
} // end method actionPerformed
// calcular y regresar al area de un circulo
public double areadelcirculo( double radio )
{
double area = ( Math.PI * Math.pow( radio, 2 ));
return area;
} // fin del metodo areadelcirculo
// calcular y regresar al diametro de un circulo
public double diametrodelcirculo( double radio )
{
double diametro = radio*2;
return diametro;
} // fin del metodo diametrodelcirculo
// calcular y regresar la circunferencia de un circulo
public double circunferenciadelcirculo( double radio )
{
double circunferencia = ((2* radio) * Math.PI);
return circunferencia;
} // fin del metodo circunferenciadelcirculo
} // fin de la clase Area

RESULTADOS DEL PROGRAMA


Problema #3 Calcular el área de un triángulo conociendo su base y altura

PROGRAMA
// Ejercicio: Area.java
// Calcular el área de un triángulo conociendo su base y su altura
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Area extends JApplet implements ActionListener {
JLabel promptLabel; JLabel promptLabel2;
JTextField inputField; JTextField inputField2;
// create GUI
public void init()
{
Container container = getContentPane();
container.setLayout( new FlowLayout() );
Container container2 = getContentPane();
container2.setLayout( new FlowLayout() );
promptLabel = new JLabel( "Escribir la base del triángulo:" );
inputField = new JTextField( 10 );
inputField.addActionListener( this );
container.add( promptLabel );
container.add( inputField );
promptLabel2 = new JLabel( "Escribir la altura del triángulo:" );
inputField2 = new JTextField( 10 );
inputField2.addActionListener( this );
container2.add( promptLabel2 );
container2.add( inputField2 );
} // end method init
// Calcular el área del triángulo
public void actionPerformed( ActionEvent actionEvent )
{
double base =
Double.parseDouble(inputField.getText() );
double altura =
Double.parseDouble(inputField2.getText() );
showStatus( " El área del triángulo es " + area2 ( base, altura));
} // end method actionPerformed
// Calcular y regresar el área del triángulo
public double area2( double base1, double altura1 )
{
double Area2 = ((base1 * altura1) / (2.0));
return Area2;
} // fin del metodo area2
} // fin de la clase Area

RESULTADOS DEL PROGRAMA


Problema #4 Calcular la hipotenusa de un triángulo rectángulo conociendo el
valor de sus catetos

PROGRAMA

// Ejercicio: Hipotenusa.java
// Calcular la hipotenusa de un triángulo rectángulo conociendo sus catetos
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Triangulo extends JApplet implements ActionListener {
JLabel promptLabel; JLabel promptLabel2;
JTextField inputField; JTextField inputField2;
// create GUI
public void init()
{
Container container = getContentPane();
container.setLayout( new FlowLayout() );
Container container2 = getContentPane();
container2.setLayout( new FlowLayout() );
promptLabel = new JLabel( "Escribir el cateto A:" );
inputField = new JTextField( 10 );
inputField.addActionListener( this );
container.add( promptLabel );
container.add( inputField );
promptLabel2 = new JLabel( "Escribir el cateto B:" );
inputField2 = new JTextField( 10 );
inputField2.addActionListener( this );
container2.add( promptLabel2 );
container2.add( inputField2 );
} // end method init
// Calcular la hipotenusa del triángulo
public void actionPerformed( ActionEvent actionEvent )
{
double catetoa =
Double.parseDouble(inputField.getText() );
double catetob =
Double.parseDouble(inputField2.getText() );
showStatus( " La hipotenusa del triángulo es " + hipotenusa ( catetoa, catetob));
} // end method actionPerformed
// Calcular y regresar a la hipotenusa del triángulo
public double hipotenusa( double cateto1, double cateto2 )
{
double Hipotenusa = Math.sqrt ( Math.pow (cateto1, 2) + Math.pow (cateto2, 2));
return Hipotenusa;
} // fin del metodo hipotenusa

RESULTADOS DEL PROGRAMA

Das könnte Ihnen auch gefallen