You are on page 1of 10

ACTIVIDAD 2

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Pru;

/**
*
* @author HELLEN
*/
import java.awt.*;
import java.applet.*;

// <applet width="200" height="200" code="Pru"></applet>

public class Pru extends Applet {


public void paint(Graphics g) {
int x;
x = 2 / 3;
g.drawString("2 / 3 = "+x, 100, 100);
}

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Pru;

/**
*
* @author HELLEN
*/

import java.awt.*;
import java.applet.*;

// <applet width="200" height="200"


code="Pru"></applet>

public class Pru extends Applet


{
public void paint(Graphics g)
{
int x;
x = 5 * 8;
g.drawString("5 * 8 = "+x, 100, 100);
}
}

SUMA +

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Pru;

/**
*
* @author HELLEN
*/
import java.awt.*;
import java.applet.*;

// <applet width="200" height="200"


code="Pru"></applet>

public class Pru extends Applet


{
public void paint(Graphics g)
{
int x;
x = 8 + 8;
g.drawString("8 + 8 = "+x, 100, 100);
}
}

RESTA

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Pru;

/**
*
* @author HELLEN
*/
import java.awt.*;
import java.applet.*;

// <applet width="200" height="200"


code="Pru"></applet>
public class Pru extends Applet
{
public void paint(Graphics g)
{
int x;
x = 10 - 6;
g.drawString("10 - 6 = "+x, 100, 100);
}
}

CONVERSION

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Conversion;

/**
*
* @author HELLEN
*/
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class Conversion extends Applet implements ActionListener


{
Label l1, l2;
TextField t1, t2;
Button b;

public Conversion()
{
l1 = new Label("Centgrados");
t1 = new TextField();
l2 = new Label("Fahrenheit");
t2 = new TextField();
b = new Button("Calcula");
add(l1);
add(t1);
add(l2);
add(t2);
add(b);
b. addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
double num = Double.parseDouble(t1.getText());
t2.setText(""+((9.0/5.0*num)+32));
}
}

CUADRADO

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

// <applet width="200" height="200" code="AppletDaCuadrado"></applet>

public class AppletDaCuadrado extends Applet implements ActionListener


{
TextField t;
Button b;

public AppletDaCuadrado()
{
t = new TextField(); // se crea el objeto texto
b = new Button("Calcula"); // se crea el boton para calcular
add(t); // se aade el texto a la pantalla
add(b); // se aade el botn a la pantalla
b. addActionListener(this); // se le aade al boton la facilidad de ser escuchado
}

public void paint(Graphics g)


{
int num = Integer.parseInt(t.getText()); // pasa texto al nmero entero
g.drawString("Cuadrado = "+num*num, 100, 100); //dibuja el cuadrado
}

public void actionPerformed(ActionEvent ae)


{
repaint(); // se le pide que se repinte la ventana
}
}

CUADRADO

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Cuadrado;

/**
*
* @author HELLEN
*/

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.lang.Math;

// <applet width="200" height="200" code="AppletCuadrado"></applet>

public class Cuadrado extends Applet implements ActionListener


{
Label l1, l2;
TextField t1, t2;
Button b;
public Cuadrado()
{
l1 = new Label("Numero");
t1 = new TextField();
l2 = new Label("Cuadrado");
t2 = new TextField();
b = new Button("Calcula");
add(l1);
add(t1);
add(l2);
add(t2);
add(b);
b. addActionListener(this);
}

public void actionPerformed(ActionEvent ae)


{
double num = Double.parseDouble(t1.getText());
t2.setText(""+Math.pow(num,2.0));
}
}

CUADRATICA

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Cuadratica;

/**
*
* @author HELLEN
*/
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.lang.Math;

public class Cuadratica extends Applet implements ActionListener


{
Label l1, l2, l3, l4, l5;
TextField t1, t2, t3, t4, t5;
Button b;

public Cuadratica()
{
l1 = new Label("a");
t1 = new TextField();
l2 = new Label("b");
t2 = new TextField();
l3 = new Label("c");
t3 = new TextField();
l4 = new Label("Raiz1");
t4 = new TextField();
l5 = new Label("Raiz2");
t5 = new TextField();
b = new Button("Calcular");
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(l4);
add(t4);
add(l5);
add(t5);
add(b);
b. addActionListener(this);
}

public void actionPerformed(ActionEvent john)


{
double a = Double.parseDouble(t1.getText());
double b = Double.parseDouble(t2.getText());
double c = Double.parseDouble(t3.getText());

double raiz = Math.pow(b,2)-(4*a*c);


t4.setText(""+((-b+Math.sqrt(raiz))/(2*a)));
t5.setText(""+((-b-Math.sqrt(raiz))/(2*a)));
}
}

PREGUNTAS PARA RESOLVER CON SUS PROPIAS PALABRAS, NO


COPIADO DE UN TEXTO.

1. QU ES UNA CLASE EN LA POO?


Una clase es un modelo con el cual se crean objetos, el modelo nos
permite describir el estado y el comportamiento de los objetos que
se encuentran en la clase.

2. QU ES UN OBJETO EN LA POO?
Un objeto es cualquier cosa que cumpla con cualquier funcin u
operaciones con las cuales se pueden definir el comportamiento y el
estado de dicho objeto.
3. QU DIFERENCIA EXISTE ENTRE UN TIPO DE DATO PRIMITIVO Y UN TIPO
DE DATO OBJETO?

RANGO
NOMBRE TIPO OCUPA
APROXIMADO

byte Entero 1 byte -128 a 127

short Entero 2 bytes -32768 a 32767

int Entero 4 bytes 2*109

long Entero 8 bytes Muy grande


TIPOS PRIMITIVOS
(sin mtodos; no son Decimal
float 4 bytes Muy grande
objetos; no necesitan simple
una invocacin para
ser creados) Decimal
double 8 bytes Muy grande
doble

Carcter
char 2 bytes ---
simple

Valor true o
boolean 1 byte ---
false

TIPOS
DE
DATOS String (cadenas de texto)
Tipos de la biblioteca
EN JAVA Muchos otros (p.ej. Scanner, TreeSet,
estndar de Java
ArrayList)

Tipos definidos por el Cualquiera que se nos ocurra, por ejemplo


programador / usuario Taxi, Autobus, Tranvia

Serie de elementos o formacin tipo vector o


arrays matriz. Lo consideraremos un objeto especial
que carece de mtodos.
TIPOS OBJETO
(con mtodos, Byte
necesitan una
invocacin para ser Short
creados)
Integer
Tipos envoltorio o
wrapper (Equivalentes Long
a los tipos primitivos Float
pero como objetos.)
Double

Character

Boolean

You might also like