Vous êtes sur la page 1sur 23

Teora de la Computacin

Reporte de: AE1 Mquina Expendedora de Refrescos


24/08/2011 Keren Snchez Salinas. Numero de control: 08410843 Valor: 5%

Simular el funcionamiento de una mquina expendedora de refrescos, utilizando un lenguaje de programacin.

1.-Detectar las funciones bsicas que llevara a cabo el programa (mtodos principales). 2.-Revizar los mtodos propuestos, y detectar mtodos secundarios. 3.-Creacin de clase en java.

4.-Creacin de interfaz grfica del programa y aadir los botones necesarios para la ejecucin del mismo.

6.-Aplicar los mtodos en modo de lenguaje de programacin, corrigiendo errores y verificando su correcto funcionamiento.

7.-Ejecucin del programa en modo correcto, tomando en cuenta las consideraciones a tomar.

A. Al ejecutar aparece la siguiente ventana, si se nota la instruccin marca que se presione inicio para comenzar, si no se desea realizar esta accin solo hay que oprimir salir. Tambin se puede notar que el botn de cancelar esta temporalmente invisible.

B. Al dar clic en el botn inicio aparece el siguiente men, con el mensaje de insertar monedas y el valor de cada moneda. Ahora se puede notar que el botn cancelar esta visible, por lo que desde este momento es posible

cancelar la operacin.

C. Ahora se ha presionado dos veces el botn de 0.10 y nos muestra el valor que tenemos hasta el momento.

D. Al sumar la cantidad de 0.45 la maquina expulsa el refresco y muestra el mensaje de que se puede tomar.

E. Al despachar el refresco vuelve a contador en ceros.

F. Ahora bien, si el valor en monedas sobrepasa a 0.45, la maquina se traga la ltima moneda que se ha introducido y muestra un mensaje dicindonos lo
7

anterior.

G. Al presionar el botn de cancelar, nos manda al men con el que se inici.

H. Y al presionar el botn de Salir nos muestra un mensaje en el que se pide la confirmacin de la accin.

I. Al presionar si el programa termina su ejecucin y vuelve a NetBeans.


Clase Main: /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package ssss;

/** * * @author Kerensita */ public class Ssss {

/** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here

menuu me = new menuu(); me.show(); } }

10

Clase JFrame: /* * To change this template, choose Tools | Templates * and open the template in the editor. */

/* * menuu.java * * Created on 23-ago-2011, 17:36:16 */ package ssss;

import java.text.DecimalFormat; import javax.swing.JOptionPane;

/** * * @author Kerensita */ public class menuu extends javax.swing.JFrame { double z=0; DecimalFormat df = new DecimalFormat("0.00");

11

/** Creates new form menuu */ public menuu() { initComponents(); }

/** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() {

jPanel1 = new javax.swing.JPanel(); uno = new javax.swing.JButton(); dos = new javax.swing.JButton(); display = new javax.swing.JLabel(); jButton1 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

12

jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorde r.RAISED));

uno.setText("Inicio"); uno.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { unoActionPerformed(evt); } });

dos.setText("Salir"); dos.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { dosActionPerformed(evt); } });

display.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); display.setText("Presione Inicio");

jButton1.setText("Cancelar"); jButton1.setEnabled(false); jButton1.addActionListener(new java.awt.event.ActionListener() {


13

public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } });

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(

jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap()

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN G) .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 154, Short.MAX_VALUE) .addComponent(display, javax.swing.GroupLayout.DEFAULT_SIZE, 154, Short.MAX_VALUE)

.addGroup(jPanel1Layout.createSequentialGroup() .addComponent(uno)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 44, Short.MAX_VALUE) .addComponent(dos)))

14

.addContainerGap()) ); jPanel1Layout.setVerticalGroup(

jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addComponent(display)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELI NE) .addComponent(uno) .addComponent(dos))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton1) .addContainerGap()) );

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
15

.addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap()) ); layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap()) );

pack(); }// </editor-fold>

private void dosActionPerformed(java.awt.event.ActionEvent evt) { if( "Salir".equals(this.dos.getText())){ int x=JOptionPane.showConfirmDialog(null, "Quieres Salir?","Salir", JOptionPane.YES_NO_OPTION); if(x==0){ System.exit(0);
16

} }else{ double x=Double.parseDouble(this.dos.getText()); if( "0.10".equals(this.dos.getText())){ if(z<0.45){ z=z+x; this.display.setText("Tiene Acumulado=$"+ String.valueOf(df.format(z))); if(z==0.45){ JOptionPane.showMessageDialog(null, "Toma Tu Refresco"); this.display.setText("Inserte Monedas"); this.uno.setText("0.25"); this.dos.setText("0.10"); z=0; } if(z>0.45){ z=z-x; this.display.setText("Tiene Acumulado=$"+ String.valueOf(df.format(z))); JOptionPane.showMessageDialog(null, "Se trago Ultima moneda","Error",JOptionPane.ERROR_MESSAGE); }

} }

}
17

private void unoActionPerformed(java.awt.event.ActionEvent evt) { if( "Inicio".equals(this.uno.getText())){ this.display.setText("Inserte Monedas"); this.uno.setText("0.25"); this.dos.setText("0.10"); this.jButton1.setEnabled(true); }else{ double x=Double.parseDouble(this.uno.getText()); if( "0.25".equals(this.uno.getText())){ if(z<0.45){ z=z+x; this.display.setText("Tiene Acumulado=$"+ String.valueOf(df.format(z))); if(z==0.45){ JOptionPane.showMessageDialog(null, "Toma Tu Refresco"); this.display.setText("Inserte Monedas"); this.uno.setText("0.25"); this.dos.setText("0.10"); z=0; } if(z>0.45){ z=z-x; this.display.setText("Tiene Acumulado=$"+ String.valueOf(df.format(z)));

18

JOptionPane.showMessageDialog(null, "Se trago Ultima moneda","Error",JOptionPane.ERROR_MESSAGE); } } } } }

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { this.uno.setText("Inicio"); this.dos.setText("Salir"); this.display.setText("Presione Inicio"); z=0; this.jButton1.setEnabled(false); }

/** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.

19

* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) {

javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) {

java.util.logging.Logger.getLogger(menuu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(menuu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(menuu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(menuu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); }


20

//</editor-fold>

/* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() {

public void run() { new menuu().setVisible(true); } }); } // Variables declaration - do not modify public javax.swing.JLabel display; public javax.swing.JButton dos; private javax.swing.JButton jButton1; public javax.swing.JPanel jPanel1; public javax.swing.JButton uno; // End of variables declaration }

21


Dada la anterior informacin se puede concluir que la simulacin resulto en el objetivo propuesto, sin embargo existieron muchas complicaciones en la realizacin de la misma, por ejemplo, el que el programa simulara los valores y que, exactamente en cierta cantidad, se ejerciera una conclusin, resulto en la realizacin de muchas maneras diferentes, muchas de las cuales sin el resultado esperado. Sin embargo, la simulacin fue un xito y este reporte es prueba de ello.

22

Vous aimerez peut-être aussi