Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package semana05;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.JLabel;
- import javax.swing.JButton;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import javax.swing.JTextField;
- import javax.swing.JScrollPane;
- import javax.swing.JTextArea;
- import javax.swing.UIManager;
- import javax.swing.JComboBox;
- import javax.swing.DefaultComboBoxModel;
- import java.awt.Font;
- public class Hotel extends JFrame implements ActionListener {
- // Declaración de variables
- private static final long serialVersionUID = 9206324162700448001L;
- private JPanel contentPane;
- private JLabel lblTipoHabitacion;
- private JLabel lblCantidadDias;
- private JComboBox<String> cboTipoHabitacion;
- private JTextField txtCantidadDias;
- private JButton btnProcesar;
- private JButton btnBorrar;
- private JScrollPane scpScroll;
- private JTextArea txtS;
- // Lanza la aplicación
- public static void main(String[] args) {
- try {
- UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
- }
- catch (Throwable e) {
- e.printStackTrace();
- }
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Hotel frame = new Hotel();
- frame.setVisible(true);
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- // Crea la GUI
- public Hotel() {
- setTitle("Hotel");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 450, 300);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- lblTipoHabitacion = new JLabel("Tipo de habitaci\u00F3n");
- lblTipoHabitacion.setBounds(10, 11, 87, 14);
- contentPane.add(lblTipoHabitacion);
- lblCantidadDias = new JLabel("Cantidad de d\u00EDas");
- lblCantidadDias.setBounds(10, 36, 80, 14);
- contentPane.add(lblCantidadDias);
- cboTipoHabitacion = new JComboBox<String>();
- cboTipoHabitacion.setModel(new DefaultComboBoxModel<String>(new String[] { "Simple", "Matrimonial", "Doble", "Triple" }));
- cboTipoHabitacion.setBounds(107, 8, 100, 20);
- contentPane.add(cboTipoHabitacion);
- txtCantidadDias = new JTextField();
- txtCantidadDias.setBounds(107, 33, 100, 20);
- contentPane.add(txtCantidadDias);
- txtCantidadDias.setColumns(10);
- btnProcesar = new JButton("Procesar");
- btnProcesar.addActionListener(this);
- btnProcesar.setBounds(335, 7, 89, 23);
- contentPane.add(btnProcesar);
- btnBorrar = new JButton("Borrar");
- btnBorrar.addActionListener(this);
- btnBorrar.setBounds(335, 32, 89, 23);
- contentPane.add(btnBorrar);
- scpScroll = new JScrollPane();
- scpScroll.setBounds(10, 61, 414, 190);
- contentPane.add(scpScroll);
- txtS = new JTextArea();
- txtS.setFont(new Font("Monospaced", Font.PLAIN, 12));
- scpScroll.setViewportView(txtS);
- }
- // Direcciona eventos de tipo ActionEvent
- public void actionPerformed(ActionEvent arg0) {
- if (arg0.getSource() == btnBorrar) {
- actionPerformedBtnBorrar(arg0);
- }
- if (arg0.getSource() == btnProcesar) {
- actionPerformedBtnProcesar(arg0);
- }
- }
- // Procesa la pulsación del botón Borrar
- protected void actionPerformedBtnBorrar(ActionEvent arg0) {
- txtCantidadDias.setText("");
- txtS.setText("");
- cboTipoHabitacion.setSelectedIndex(0);
- txtCantidadDias.requestFocus();
- }
- // Procesa la pulsación del botón Procesar
- protected void actionPerformedBtnProcesar(ActionEvent arg0) {
- // Declaración de variables
- int mod, cand, lapr = 0;
- double imsu = 0, ides = 0, ipag;
- // Entrada de datos
- mod = cboTipoHabitacion.getSelectedIndex();
- cand = Integer.parseInt(txtCantidadDias.getText());
- // Cálculo del importe subtotal
- if (mod == 0)
- imsu = 80.0 * cand;
- if (mod == 1)
- imsu = 130.0 * cand;
- if (mod == 2)
- imsu = 140.0 * cand;
- if (mod == 3)
- imsu = 180.0 * cand;
- // Cálculo del importe descuento
- if (cand >= 12)
- ides = 0.075 * imsu;
- if (cand >= 6 && cand < 12)
- ides = 0.05 * imsu;
- if (cand >= 3 && cand < 6)
- ides = 0.25 * imsu;
- if (cand < 3)
- ides = 0;
- // Cálculo del importe a pagar
- ipag = imsu - ides;
- // Cálculo de lapiceros
- if (ipag < 100)
- lapr = 2 * cand;
- if (ipag >= 100 && ipag < 150)
- lapr = 3 * cand;
- if (ipag >= 150)
- lapr = 4 * cand;
- // Salida de texto
- txtS.setText("SALIDA DE DATOS: " + "\n");
- txtS.append("Importe subtotal = " + imsu + "\n");
- txtS.append("Importe del descuento = " + ides + "\n");
- txtS.append("Importe a pagar = " + ipag + "\n");
- txtS.append("Lapiceros de regalo = " + lapr + "\n");
- }
- }
- ---------------------------------------------------------------------------------------------
- package semana05;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.JLabel;
- import javax.swing.JButton;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import javax.swing.JTextField;
- import javax.swing.JScrollPane;
- import javax.swing.JTextArea;
- import javax.swing.UIManager;
- import javax.swing.JComboBox;
- import javax.swing.DefaultComboBoxModel;
- import java.awt.Font;
- public class Libreria extends JFrame implements ActionListener {
- // Declaración de variables
- private static final long serialVersionUID = 9206324162700448001L;
- private JPanel contentPane;
- private JLabel lblMarca;
- private JLabel lblCantidad;
- private JComboBox<String> cboMarca;
- private JTextField txtCantidad;
- private JButton btnProcesar;
- private JButton btnBorrar;
- private JScrollPane scpScroll;
- private JTextArea txtS;
- // Lanza la aplicación
- public static void main(String[] args) {
- try {
- UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
- }
- catch (Throwable e) {
- e.printStackTrace();
- }
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Libreria frame = new Libreria();
- frame.setVisible(true);
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- // Crea la GUI
- public Libreria() {
- setTitle("Librer\u00EDa");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 450, 233);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- lblMarca = new JLabel("Marca");
- lblMarca.setBounds(10, 11, 47, 14);
- contentPane.add(lblMarca);
- lblCantidad = new JLabel("Cantidad");
- lblCantidad.setBounds(10, 36, 47, 14);
- contentPane.add(lblCantidad);
- cboMarca = new JComboBox<String>();
- cboMarca.setModel(new DefaultComboBoxModel<String>(new String[] { "Standford", "Alpha", "Justus", "Loro" }));
- cboMarca.setBounds(67, 8, 100, 20);
- contentPane.add(cboMarca);
- txtCantidad = new JTextField();
- txtCantidad.setBounds(67, 33, 100, 20);
- contentPane.add(txtCantidad);
- txtCantidad.setColumns(10);
- btnProcesar = new JButton("Procesar");
- btnProcesar.addActionListener(this);
- btnProcesar.setBounds(335, 7, 89, 23);
- contentPane.add(btnProcesar);
- btnBorrar = new JButton("Borrar");
- btnBorrar.addActionListener(this);
- btnBorrar.setBounds(335, 32, 89, 23);
- contentPane.add(btnBorrar);
- scpScroll = new JScrollPane();
- scpScroll.setBounds(10, 61, 414, 123);
- contentPane.add(scpScroll);
- txtS = new JTextArea();
- txtS.setFont(new Font("Monospaced", Font.PLAIN, 12));
- scpScroll.setViewportView(txtS);
- }
- // Direcciona eventos de tipo ActionEvent
- public void actionPerformed(ActionEvent arg0) {
- if (arg0.getSource() == btnBorrar) {
- actionPerformedBtnBorrar(arg0);
- }
- if (arg0.getSource() == btnProcesar) {
- actionPerformedBtnProcesar(arg0);
- }
- }
- // Procesa la pulsación del botón Borrar
- protected void actionPerformedBtnBorrar(ActionEvent arg0) {
- txtCantidad.setText("");
- txtS.setText("");
- cboMarca.setSelectedIndex(0);
- txtCantidad.requestFocus();
- }
- // Procesa la pulsación del botón Procesar
- protected void actionPerformedBtnProcesar(ActionEvent arg0) {
- // Declaración de variables
- int mod, can;
- double icom = 0, ides = 0, ipag;
- // Entrada de datos
- mod = cboMarca.getSelectedIndex();
- can = Integer.parseInt(txtCantidad.getText());
- // Cálculo del importe compra
- if (mod == 0)
- icom = 4.85 * can;
- if (mod == 1)
- icom = 4.35 * can;
- if (mod == 2)
- icom = 3.50 * can;
- if (mod == 3)
- icom = 4.55 * can;
- // Cálculo del importe descuento
- if (can >= 36)
- ides = 0.135 * icom;
- if (can >= 24 && can < 36)
- ides = 0.115 * icom;
- if (can >= 12 && can < 24)
- ides = 0.095 * icom;
- if (can < 12)
- ides = 0.075 * icom;
- // Cálculo del importe a pagar
- ipag = icom - ides;
- // Salida de texto
- txtS.setText("SALIDA DE DATOS: " + "\n");
- txtS.append("Importe de compra = " + icom + "\n");
- txtS.append("Importe del descuento = " + ides + "\n");
- txtS.append("Importe a pagar = " + ipag + "\n");
- }
- }
- --------------------------------------------------------------------------------------------------------------
- package semana05;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.JLabel;
- import javax.swing.JButton;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import javax.swing.JTextField;
- import javax.swing.JScrollPane;
- import javax.swing.JTextArea;
- import javax.swing.UIManager;
- import javax.swing.JComboBox;
- import javax.swing.DefaultComboBoxModel;
- import java.awt.Font;
- public class Mochila extends JFrame implements ActionListener {
- // Declaración de variables
- private static final long serialVersionUID = 9206324162700448001L;
- private JPanel contentPane;
- private JLabel lblModelo;
- private JLabel lblCantidad;
- private JComboBox<String> cboModelo;
- private JTextField txtCantidad;
- private JButton btnProcesar;
- private JButton btnBorrar;
- private JScrollPane scpScroll;
- private JTextArea txtS;
- // Lanza la aplicación
- public static void main(String[] args) {
- try {
- UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
- }
- catch (Throwable e) {
- e.printStackTrace();
- }
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Mochila frame = new Mochila();
- frame.setVisible(true);
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- // Crea la GUI
- public Mochila() {
- setTitle("Tienda");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 450, 300);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- lblModelo = new JLabel("Modelo");
- lblModelo.setBounds(10, 11, 65, 14);
- contentPane.add(lblModelo);
- lblCantidad = new JLabel("Cantidad");
- lblCantidad.setBounds(10, 36, 65, 14);
- contentPane.add(lblCantidad);
- cboModelo = new JComboBox<String>();
- cboModelo.setModel(new DefaultComboBoxModel<String>(new String[] { "Sherman", "Faguo", "Aldo", "Suburban" }));
- cboModelo.setBounds(85, 8, 100, 20);
- contentPane.add(cboModelo);
- txtCantidad = new JTextField();
- txtCantidad.setBounds(85, 33, 100, 20);
- contentPane.add(txtCantidad);
- txtCantidad.setColumns(10);
- btnProcesar = new JButton("Procesar");
- btnProcesar.addActionListener(this);
- btnProcesar.setBounds(335, 7, 89, 23);
- contentPane.add(btnProcesar);
- btnBorrar = new JButton("Borrar");
- btnBorrar.addActionListener(this);
- btnBorrar.setBounds(335, 32, 89, 23);
- contentPane.add(btnBorrar);
- scpScroll = new JScrollPane();
- scpScroll.setBounds(10, 61, 414, 190);
- contentPane.add(scpScroll);
- txtS = new JTextArea();
- txtS.setFont(new Font("Monospaced", Font.PLAIN, 12));
- scpScroll.setViewportView(txtS);
- }
- // Direcciona eventos de tipo ActionEvent
- public void actionPerformed(ActionEvent arg0) {
- if (arg0.getSource() == btnBorrar) {
- actionPerformedBtnBorrar(arg0);
- }
- if (arg0.getSource() == btnProcesar) {
- actionPerformedBtnProcesar(arg0);
- }
- }
- // Procesa la pulsación del botón Borrar
- protected void actionPerformedBtnBorrar(ActionEvent arg0) {
- txtCantidad.setText("");
- txtS.setText("");
- cboModelo.setSelectedIndex(0);
- txtCantidad.requestFocus();
- }
- // Procesa la pulsación del botón Procesar
- protected void actionPerformedBtnProcesar(ActionEvent arg0) {
- // Declaración de variables
- int mod, can, cho = 0;
- double icom = 0, ides = 0, ipag;
- String reg;
- // Entrada de datos
- mod = cboModelo.getSelectedIndex();
- can = Integer.parseInt(txtCantidad.getText());
- // Cálculo del importe compra
- if (mod == 0)
- icom = 149.9 * can;
- if (mod == 1)
- icom = 89.9 * can;
- if (mod == 2)
- icom = 119.9 * can;
- if (mod == 3)
- icom = 174.9 * can;
- // Cálculo del importe descuento
- if (can > 5)
- ides = 0;
- if (can >= 5 && can < 10)
- ides = 0.05 * icom;
- if (can >= 10 && can < 20)
- ides = 0.07 * icom;
- if (can >= 20)
- ides = 0.09 * icom;
- // Cálculo del importe a pagar
- ipag = icom - ides;
- // Cálculo de chocolates
- if (ipag < 200)
- cho = 0;
- if (ipag >= 200 && ipag < 500)
- cho = 1 * can;
- if (ipag >= 500 && ipag < 700)
- cho = 2 * can;
- if (ipag >= 700)
- cho = 3 * can;
- // Determinación del regalo adicional
- if (can < 24)
- reg = "Agenda";
- else
- reg = "Ninguno";
- // Salida de texto
- txtS.setText("SALIDA DE DATOS: " + "\n");
- txtS.append("Importe de compra = " + icom + "\n");
- txtS.append("Importe del descuento = " + ides + "\n");
- txtS.append("Importe a pagar = " + ipag + "\n");
- txtS.append("Cantidad de chocolates = " + cho + "\n");
- txtS.append("Regalo = " + reg + "\n");
- }
- }
- ---------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement