Entrega Calculadora - Sergio Bohada - 20191020033

Descargar como docx, pdf o txt
Descargar como docx, pdf o txt
Está en la página 1de 12

ENTREGA 1: CALCULADORA

SERGIO DAVID BOHADA VARGAS


COD:20191020033

JULIO BARON VELANDIA

DOCENTE INGENIERIA DE SISTEMAS

UNIVERSIDAD DISTRITAL FRANCISCO JOSÉ DE CALDAS


FACULTAD DE INGENIERÍA
INGENIERIA SISTEMAS
BOGOTA D.C
2022
Paquete: co.Calculadora.POA;
Clase madre: Calculadora.java

package co.Calculadora.POA;

public class Calculadora {

private double num1;


private double num2;
private double res;

public Calculadora(double num1,double num2) {

this.num1 = num1;
this.num2 = num2;

public double getNum1() {


return num1;
}

public void setNum1(double num1) {


this.num1 = num1;
}

public double getNum2() {


return num2;
}

public void setNum2(double num2) {


this.num2 = num2;
}

public double getRes() {


return res;
}

public void setRes(double res) {


this.res = res;
}

public void ac() {

this.res = 0;
this.num1 = 0;
this.num2 = 0;

}
public String showRes() {

String res = String.valueOf(this.res);

return res;
}

Paquete: co.Calculadora.POA;
Clase hija: Operaciones.java

package co.Calculadora.POA;

public class Operaciones extends Calculadora{

public Operaciones(double num1, double num2) {


super(num1, num2);
}

public void suma() {

System.out.println("Metodo suma --"+" Variable Num1:


"+super.getNum1()+" -- "+"Variable Num2: "+super.getNum2());
super.setRes(super.getNum1()+super.getNum2());
System.out.println("Resultado suma: "+super.getRes());

public void resta() {

System.out.println("Metodo resta --"+" Variable Num1:


"+super.getNum1()+" -- "+"Variable Num2: "+super.getNum2());
super.setRes(super.getNum1()-super.getNum2());
System.out.println("Resultado resta: "+super.getRes());

public void mult() {

System.out.println("Metodo Mult --"+" Variable Num1:


"+super.getNum1()+" -- "+"Variable Num2: "+super.getNum2());
super.setRes(super.getNum1()*super.getNum2());
System.out.println("Resultado mult: "+super.getRes());
}

public void div() {

System.out.println("Metodo div --"+" Variable Num1:


"+super.getNum1()+" -- "+"Variable Num2: "+super.getNum2());
super.setRes(super.getNum1()/super.getNum2());
System.out.println("Resultado div: "+super.getRes());

public void poten() {

System.out.println("Metodo pot --"+" Variable Num1:


"+super.getNum1()+" -- "+"Variable Num2: "+super.getNum2());
super.setRes(Math.pow(getNum1(), getNum2()));
System.out.println("Resultado pot: "+super.getRes());

public void rad() {

System.out.println("Metodo pot --"+" Variable Num1:


"+super.getNum1()+" -- "+"Variable Num2: "+super.getNum2());
super.setRes(Math.pow(getNum1(), 1/getNum2()));
System.out.println("Resultado pot: "+super.getRes());

public String res() {

String res = String.valueOf(super.getRes());


System.out.println("Variable res: "+super.getRes());

return res;
}

Paquete: co.Calculadora.POA;
Clase vista: Operaciones.java

package co.Calculadora.POA;
import java.awt.Color;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;
import javax.swing.JButton;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JLabel;

public class Vista {

private JFrame frame;


private JTextField textField_nums;
private Calculadora cal = new Calculadora(0,0);
private Operaciones op;
private JLabel lblNewLabel_res = new JLabel("", SwingConstants.CENTER);
private int cont = 0;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Vista window = new Vista();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Create the application.
*/
public Vista() {
initialize();
}

/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 398, 472);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);

textField_nums = new JTextField();


textField_nums.setBounds(0, 0, 167, 82);
textField_nums.setBorder(new LineBorder(Color.GRAY,1));
frame.getContentPane().add(textField_nums);
textField_nums.setColumns(10);

JButton btnNewButtonAC = new JButton("A/C");


btnNewButtonAC.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cal.ac();
lblNewLabel_res.setText("");

}
});
btnNewButtonAC.setFont(new Font("Microsoft JhengHei UI Light",
Font.PLAIN, 11));
btnNewButtonAC.setForeground(Color.WHITE);
btnNewButtonAC.setBounds(0, 82, 130, 58);
btnNewButtonAC.setBackground(new Color(48, 186, 255));
btnNewButtonAC.setBorderPainted(false);
frame.getContentPane().add(btnNewButtonAC);

JButton btnNewButton_suma = new JButton("+");


btnNewButton_suma.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
op = new Operaciones(cal.getNum1(),cal.getNum2());
op.suma();
lblNewLabel_res.setText(op.showRes());
}
});
btnNewButton_suma.setForeground(Color.WHITE);
btnNewButton_suma.setFont(new Font("Microsoft JhengHei UI Light",
Font.PLAIN, 11));
btnNewButton_suma.setBounds(254, 82, 130, 58);
btnNewButton_suma.setBackground(new Color(48, 186, 255));
btnNewButton_suma.setBorderPainted(false);
frame.getContentPane().add(btnNewButton_suma);

JButton btnNewButton_mult = new JButton("x");


btnNewButton_mult.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

op = new Operaciones(cal.getNum1(),cal.getNum2());
op.mult();
lblNewLabel_res.setText(op.showRes());
}
});
btnNewButton_mult.setBackground(new Color(48, 186, 255));
btnNewButton_mult.setForeground(Color.WHITE);
btnNewButton_mult.setFont(new Font("Microsoft YaHei UI Light",
Font.PLAIN, 11));
btnNewButton_mult.setBounds(255, 194, 130, 58);
btnNewButton_mult.setBorderPainted(false);
frame.getContentPane().add(btnNewButton_mult);

JButton btnNewButton_resta = new JButton("-");


btnNewButton_resta.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
op = new Operaciones(cal.getNum1(),cal.getNum2());
op.resta();
lblNewLabel_res.setText(op.showRes());
}
});
btnNewButton_resta.setBackground(new Color(48, 186, 255));
btnNewButton_resta.setForeground(Color.WHITE);
btnNewButton_resta.setFont(new Font("Microsoft YaHei UI Light",
Font.PLAIN, 11));
btnNewButton_resta.setBounds(255, 138, 130, 58);
btnNewButton_resta.setBorderPainted(false);
frame.getContentPane().add(btnNewButton_resta);

JButton btnNewButton_div = new JButton("/");


btnNewButton_div.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
op = new Operaciones(cal.getNum1(),cal.getNum2());
op.div();
lblNewLabel_res.setText(op.showRes());
}
});
btnNewButton_div.setBackground(new Color(48, 186, 255));
btnNewButton_div.setFont(new Font("Microsoft JhengHei UI Light",
Font.PLAIN, 11));
btnNewButton_div.setForeground(Color.WHITE);
btnNewButton_div.setBounds(255, 251, 130, 58);
btnNewButton_div.setBorderPainted(false);
frame.getContentPane().add(btnNewButton_div);
JButton btnNewButtonAC_1 = new JButton("1");
btnNewButtonAC_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textField_nums.setText(textField_nums.getText()+"1");
}
});
btnNewButtonAC_1.setBackground(Color.WHITE);
btnNewButtonAC_1.setFont(new Font("Microsoft YaHei UI Light",
Font.PLAIN, 11));
btnNewButtonAC_1.setForeground(Color.BLACK);
btnNewButtonAC_1.setBounds(0, 138, 130, 58);
btnNewButtonAC_1.setBorderPainted(false);
frame.getContentPane().add(btnNewButtonAC_1);

JButton btnNewButtonAC_2 = new JButton("2");


btnNewButtonAC_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textField_nums.setText(textField_nums.getText()+"2");

}
});
btnNewButtonAC_2.setBackground(Color.WHITE);
btnNewButtonAC_2.setFont(new Font("Microsoft YaHei UI Light",
Font.PLAIN, 11));
btnNewButtonAC_2.setForeground(Color.BLACK);
btnNewButtonAC_2.setBounds(127, 138, 130, 58);
btnNewButtonAC_2.setBorderPainted(false);
frame.getContentPane().add(btnNewButtonAC_2);

JButton btnNewButtonAC_3 = new JButton("3");


btnNewButtonAC_3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textField_nums.setText(textField_nums.getText()+"3");
}
});
btnNewButtonAC_3.setBackground(Color.WHITE);
btnNewButtonAC_3.setFont(new Font("Microsoft YaHei UI Light",
Font.PLAIN, 11));
btnNewButtonAC_3.setForeground(Color.BLACK);
btnNewButtonAC_3.setBounds(0, 194, 130, 58);
btnNewButtonAC_3.setBorderPainted(false);
frame.getContentPane().add(btnNewButtonAC_3);

JButton btnNewButtonAC_4 = new JButton("4");


btnNewButtonAC_4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textField_nums.setText(textField_nums.getText()+"4");
}
});
btnNewButtonAC_4.setBackground(Color.WHITE);
btnNewButtonAC_4.setFont(new Font("Microsoft YaHei UI Light",
Font.PLAIN, 11));
btnNewButtonAC_4.setForeground(Color.BLACK);
btnNewButtonAC_4.setBounds(127, 194, 130, 58);
btnNewButtonAC_4.setBorderPainted(false);
frame.getContentPane().add(btnNewButtonAC_4);

JButton btnNewButtonAC_5 = new JButton("5");


btnNewButtonAC_5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textField_nums.setText("5");
}
});
btnNewButtonAC_5.setBackground(Color.WHITE);
btnNewButtonAC_5.setFont(new Font("Microsoft YaHei UI Light",
Font.PLAIN, 11));
btnNewButtonAC_5.setForeground(Color.BLACK);
btnNewButtonAC_5.setBounds(0, 251, 130, 58);
btnNewButtonAC_5.setBorderPainted(false);
frame.getContentPane().add(btnNewButtonAC_5);

JButton btnNewButtonAC_6 = new JButton("6");


btnNewButtonAC_6.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textField_nums.setText(textField_nums.getText()+"6");
}
});
btnNewButtonAC_6.setBackground(Color.WHITE);
btnNewButtonAC_6.setFont(new Font("Microsoft YaHei UI Light",
Font.PLAIN, 11));
btnNewButtonAC_6.setForeground(Color.BLACK);
btnNewButtonAC_6.setBounds(127, 251, 130, 58);
btnNewButtonAC_6.setBorderPainted(false);
frame.getContentPane().add(btnNewButtonAC_6);

JButton btnNewButtonAC_7 = new JButton("7");


btnNewButtonAC_7.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textField_nums.setText(textField_nums.getText()+"7");
}
});
btnNewButtonAC_7.setBackground(Color.WHITE);
btnNewButtonAC_7.setFont(new Font("Microsoft YaHei UI Light",
Font.PLAIN, 11));
btnNewButtonAC_7.setForeground(Color.BLACK);
btnNewButtonAC_7.setBounds(0, 308, 130, 58);
btnNewButtonAC_7.setBorderPainted(false);
frame.getContentPane().add(btnNewButtonAC_7);

JButton btnNewButtonAC_8 = new JButton("8");


btnNewButtonAC_8.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textField_nums.setText(textField_nums.getText()+"8");
}
});
btnNewButtonAC_8.setBackground(Color.WHITE);
btnNewButtonAC_8.setFont(new Font("Microsoft YaHei UI Light",
Font.PLAIN, 11));
btnNewButtonAC_8.setForeground(Color.BLACK);
btnNewButtonAC_8.setBounds(127, 308, 130, 58);
btnNewButtonAC_8.setBorderPainted(false);
frame.getContentPane().add(btnNewButtonAC_8);

JButton btnNewButtonAC_9 = new JButton("9");


btnNewButtonAC_9.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textField_nums.setText(textField_nums.getText()+"9");
}
});
btnNewButtonAC_9.setBackground(Color.WHITE);
btnNewButtonAC_9.setFont(new Font("Microsoft YaHei UI Light",
Font.PLAIN, 11));
btnNewButtonAC_9.setForeground(Color.BLACK);
btnNewButtonAC_9.setBounds(0, 364, 130, 58);
btnNewButtonAC_9.setBorderPainted(false);
frame.getContentPane().add(btnNewButtonAC_9);

JButton btnNewButtonAC_0 = new JButton("0");


btnNewButtonAC_0.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textField_nums.setText(textField_nums.getText()+"0");
}
});
btnNewButtonAC_0.setBackground(Color.WHITE);
btnNewButtonAC_0.setFont(new Font("Microsoft YaHei UI Light",
Font.PLAIN, 11));
btnNewButtonAC_0.setForeground(Color.BLACK);
btnNewButtonAC_0.setBounds(127, 364, 130, 58);
btnNewButtonAC_0.setBorderPainted(false);
frame.getContentPane().add(btnNewButtonAC_0);

JButton btnNewButton_Poten = new JButton("Set");


btnNewButton_Poten.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cont++;
switch(cont) {
case 1:
cal.setNum1(Double.parseDouble(textField_nums.getText()));
System.out.println("Entró caso 1 -- Num 1: "+cal.getNum1());
break;
case 2:
cal.setNum2(Double.parseDouble(textField_nums.getText()));
System.out.println("Entró caso 2 -- Num 2: "+cal.getNum2());
break;

if (cont > 2) {

cont = 0;
}

textField_nums.setText(null);

}
});
btnNewButton_Poten.setBackground(new Color(48, 186, 255));
btnNewButton_Poten.setForeground(Color.WHITE);
btnNewButton_Poten.setFont(new Font("Microsoft YaHei UI Light",
Font.PLAIN, 11));
btnNewButton_Poten.setBounds(255, 308, 130, 58);
btnNewButton_Poten.setBorderPainted(false);
frame.getContentPane().add(btnNewButton_Poten);

JButton btnNewButton_Rad = new JButton("Rad");


btnNewButton_Rad.setBackground(new Color(48, 186, 255));
btnNewButton_Rad.setForeground(Color.WHITE);
btnNewButton_Rad.setFont(new Font("Microsoft JhengHei UI Light",
Font.PLAIN, 11));
btnNewButton_Rad.setBounds(255, 364, 130, 58);
btnNewButton_Rad.setBorderPainted(false);
frame.getContentPane().add(btnNewButton_Rad);

lblNewLabel_res.setBackground(Color.WHITE);
lblNewLabel_res.setForeground(Color.BLACK);
lblNewLabel_res.setFont(new Font("Microsoft JhengHei UI Light",
Font.PLAIN, 17));
lblNewLabel_res.setBounds(166, 0, 218, 82);
frame.getContentPane().add(lblNewLabel_res);

JButton btnNewButton_igual = new JButton("=");


btnNewButton_igual.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String res = String.valueOf(cal.getRes());
System.out.println(res);
//lblNewLabel_res.setText(String.valueOf(cal.getRes()));
}
});
btnNewButton_igual.setFont(new Font("Microsoft YaHei UI Light",
Font.PLAIN, 11));
btnNewButton_igual.setBounds(127, 82, 130, 58);
btnNewButton_igual.setBackground(new Color(48, 186, 255));
btnNewButton_igual.setForeground(Color.WHITE);
btnNewButton_igual.setBorderPainted(false);
frame.getContentPane().add(btnNewButton_igual);

}
}

También podría gustarte