teoría de la computación1

Post on 04-Mar-2015

137 Views

Category:

Documents

6 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Teoría de la Computación Reporte de: AE1 Máquina Expendedora de Refrescos 24/08/2011 Keren Sánchez Salinas. Numero de control: 08410843 Valor: 5%

1

Í

ó

ó

2

Simular el funcionamiento de una máquina expendedora de refrescos, utilizando

un lenguaje de programación.

1.-Detectar las funciones básicas que llevara a cabo el programa (métodos

principales).

2.-Revizar los métodos propuestos, y detectar métodos secundarios.

3.-Creación de clase en java.

3

4.-Creación de interfaz gráfica del programa y añadir los botones necesarios para

la ejecución del mismo.

6.-Aplicar los métodos en modo de lenguaje de programación, corrigiendo errores

y verificando su correcto funcionamiento.

4

7.-Ejecución del programa en modo correcto, tomando en cuenta las

consideraciones a tomar.

5

A. Al ejecutar aparece la siguiente ventana, si se nota la instrucción marca que

se presione inicio para comenzar, si no se desea realizar esta acción solo

hay que oprimir salir. También se puede notar que el botón de cancelar esta

temporalmente invisible.

B. Al dar clic en el botón “inicio” aparece el siguiente menú, con el mensaje de

insertar monedas y el valor de cada moneda. Ahora se puede notar que el

botón cancelar esta visible, por lo que desde este momento es posible

6

cancelar la operación.

C. Ahora se ha presionado dos veces el botón de “0.10” y nos muestra el valor

que tenemos hasta el momento.

7

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 diciéndonos lo

8

anterior.

G. Al presionar el botón de “cancelar”, nos manda al menú con el que se inició.

9

H. Y al presionar el botón de “Salir” nos muestra un mensaje en el que se pide

la confirmación de la acción.

I. Al presionar “si” el programa termina su ejecución y vuelve a NetBeans.

10

ó

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();

}

}

11

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");

12

/** 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);

13

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() {

14

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)))

15

.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)

16

.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);

17

}

}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);

}

}

}

}

18

}

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)));

19

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.

20

* 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);

}

21

//</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

}

22

Ó

Dada la anterior información se puede concluir que la simulación resulto en el

objetivo propuesto, sin embargo existieron muchas complicaciones en la

realización de la misma, por ejemplo, el que el programa simulara los valores y

que, exactamente en cierta cantidad, se ejerciera una conclusión, resulto en la

realización de muchas maneras diferentes, muchas de las cuales sin el

resultado esperado.

Sin embargo, la simulación fue un éxito y este reporte es prueba de ello.

top related