Está en la página 1de 13

Subsecretara de Educacin Superior

Direccin General de Educacin Superior Tecnolgica

INSTITUTO TECNOLGICO DE SALINA CRUZ

INGENIERA EN TECNOLOGIAS DE LA INFORMACION Y DE LAS COMUNICACIONES

MATERIA

PROGRAMACION ORIENTADA A OBJETOS

PROFESORA MC. SUSANA MONICA ROMAN NAJERA

TEMA REPORTE DE PROYECTO FINAL (CALCULADORA BASICA)

ALUMNO MEJIA BALAN FRANCISCO SABINO

SALINA CRUZ, OAXACA A 30 DE MAYO DEL 2012

INTRODUCCION
Este proyecto se realizo en el lenguaje java y en un entorno de desarrollo llamado bluej, este proyecto tiene de nombre calculadora bsica ya que realiza operaciones de suma, resta, multiplicacin y divisin. En este proyecto se utilizo las herramientas del lenguaje java, las cuales fueron las aprendidas en las unidades de la materia programacin orientada a objetos, utilizando clases predefinidas se realizo las operaciones antes mencionadas, en lo siguiente veremos el desarrollo del proyecto.

DESARROLLO
1.- COMO PRIMER PASO PONDREMOS LAS LIBRERIAS QUE UTILIZAREMOS PARA
CREAR EL CODIGO. import java.awt.*; import java.applet.*; import java.awt.event.*; import java.lang.Math; 2.- COMO SEGUNDO PASO CREAREMOS UNA CLASE LLAMADA PANEL Y AY NOMBRAREMOS DE QUE TIPO SERAN LAS VARIABLES. public class panel extends Applet implements ActionListener{ Button b1, b2, b3, b4, b5, b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18; TextField t1; Panel p2; Float n, s; // variables para uso dentro de todo el applet int y; // variables para la comparcion

3.- DE LA CLASE PANEL NOMBRAREMOS LOS NUMEROS Y OPERADORES QUE SE UTILIZARAN Y MOSTRARA LA CALCULADORA. public panel() { // panel setLayout(new BorderLayout());

p2 = new Panel(new GridLayout(6,3,10,10)); t1 = new TextField("",20); b1 = new Button("1"); b2 = new Button("2"); b3 = new Button("3"); b4 = new Button("4"); b5 = new Button("5"); b6 = new Button("6");

b7 = new Button("7"); b8 = new Button("8"); b9 = new Button("9"); b10 = new Button("."); b11 = new Button("0"); b12 = new Button("CE"); b13 = new Button("+"); b14 = new Button("-"); b15 = new Button("="); b16 = new Button("*"); b17 = new Button("/"); b18 = new Button ("C"); p2.add(b1); p2.add(b2); p2.add(b3); p2.add(b4); p2.add(b5); p2.add(b6); p2.add(b7); p2.add(b8); p2.add(b9); p2.add(b10); p2.add(b11); p2.add(b12); p2.add(b13); p2.add(b14); p2.add(b15); p2.add(b16);

p2.add(b17); p2.add(b18); add(t1,BorderLayout.NORTH); add(p2,BorderLayout.CENTER); b1.addActionListener (this); b2.addActionListener (this); b3.addActionListener (this); b4.addActionListener (this); b5.addActionListener (this); b6.addActionListener (this); b7.addActionListener (this); b8.addActionListener (this); b9.addActionListener (this); b10.addActionListener (this); b11.addActionListener (this); b12.addActionListener (this); b13.addActionListener (this); b14.addActionListener (this); b15.addActionListener (this); b16.addActionListener (this); b17.addActionListener (this); b18.addActionListener (this);

4.- EN ESTE AVENCE SE MOSTRARA LAS FORMAS DE MOSTRAR LOS NUMEROS EN PANTALLA.

} public void actionPerformed(ActionEvent ae) { String a = new String ("1"); if (ae.getSource()== b1){ // para agregar el numero indicado en comillas al cuadro de texto t1.setText(""+t1.getText()+"1");

if (ae.getSource()== b2){ // para agregar el numero indicado en comillas al cuadro de texto t1.setText(""+t1.getText()+"2"); }

if (ae.getSource()== b3){ // para agregar el numero indicado en comillas al cuadro de texto t1.setText(""+t1.getText()+"3"); }

if (ae.getSource()== b4){// para agregar el numero indicado en comillas al cuadro de texto t1.setText(""+t1.getText()+"4"); }

if (ae.getSource()== b5){// para agregar el numero indicado en comillas al cuadro de texto t1.setText(""+t1.getText()+"5");

if (ae.getSource()== b6){// para agregar el numero indicado en comillas al cuadro de texto t1.setText(""+t1.getText()+"6"); }

if (ae.getSource()== b7){// para agregar el numero indicado en comillas al cuadro de texto t1.setText(""+t1.getText()+"7"); } if (ae.getSource()== b8){// para agregar el numero indicado en comillas al cuadro de texto t1.setText(""+t1.getText()+"8"); } if (ae.getSource()== b9){// para agregar el numero indicado en comillas al cuadro de texto t1.setText(""+t1.getText()+"9"); } if (ae.getSource()== b10){ t1.setText(""+t1.getText()+"."); // agrega un punto b10.setEnabled(false); // desactiva el uso del punto } if (ae.getSource()== b11){// para agregar el numero indicado en comillas al cuadro de texto t1.setText(""+t1.getText()+"0"); } if (ae.getSource()== b12){

t1.setText(""); } 5.- EN ESTE AVANCE SE CALCULA LAS OPERACIONES A REALIZAR.

if (ae.getSource()== b13){// suma if(t1.getText()!=""){ n = Float.parseFloat(t1.getText()); y=1; } t1.setText(""); b10.setEnabled(true); // activa el uso del punto

} if (ae.getSource()== b15){ // Boton de igual if(t1.getText()!="" && y == 1){ // para sumar s = Float.parseFloat(t1.getText()); t1.setText(""+(n+s)); b10.setEnabled(true); }

if(t1.getText()!="" && y == 2){ // para restar s = Float.parseFloat(t1.getText()); t1.setText(""+(n-s)); b10.setEnabled(true);

} if(t1.getText()!="" && y == 3){ // para multiplicar s = Float.parseFloat(t1.getText()); t1.setText(""+(n*s)); b10.setEnabled(true); } if(t1.getText()!="" && y == 4){ // para divdir s = Float.parseFloat(t1.getText()); t1.setText(""+(n/s)); b10.setEnabled(true); }

} if (ae.getSource()== b14){ // resta if(t1.getText()!=""){ n = Float.parseFloat(t1.getText()); y=2; } t1.setText(""); b10.setEnabled(true);

} if (ae.getSource()== b16){ // multiplica

if(t1.getText()!=""){ n = Float.parseFloat(t1.getText()); y=3; } t1.setText(""); b10.setEnabled(true);

} if (ae.getSource()== b17){ // divide if(t1.getText()!=""){ n = Float.parseFloat(t1.getText()); y=4; } t1.setText(""); b10.setEnabled(true);

} if (ae.getSource()== b18){ // borrar todo n = null; // anula el valor de la variable en este punto t1.setText("");

} }

6.- EN ESTE AVANCE SE PRUEBA LA CALCULADORA.

7.- AQU SE REALIZA UNA OPERACIN PARA COMPROBAR LA CALCULADORA.

CONCLUSION

Concluimos que en este proyecto fueron utilizados los conocimientos adquiridos en las unidades de la materia por lo que ayudo mucho en el desarrollo de este mismo el cual termino siendo un xito.

También podría gustarte