Semana 14
Materia: Taller de Programación Orientada a Objetos
Hora: Jueves M1-M2
setTitle("Nutrilife"); jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/nutrilife/gui/logo_1201.png"))); // NOI18N jLabel2.setFont(new java.awt.Font("DejaVu Sans", 1, 48)); // NOI18N jLabel2.setText("Bienvenido a Nutrilife! "); jButton1.setFont(new java.awt.Font("DejaVu Sans Light", 1, 18)); jButton1.setText("NUEVO PACIENTE"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); }
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { PacienteGUI form = new PacienteGUI(); form.setVisible(true); }
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { PacienteGUI form = new PacienteGUI(); form.setVisible(true); this.dispose(); }
private void initComponents() { jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jButton4 = new javax.swing.JButton(); jButton5 = new javax.swing.JButton(); jButton6 = new javax.swing.JButton(); jButton7 = new javax.swing.JButton(); jButton8 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Nutrilife"); jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/nutrilife/gui/logo_1201.png"))); // NOI18N jLabel2.setFont(new java.awt.Font("DejaVu Sans", 1, 48)); // NOI18N jLabel2.setText("Bienvenido a Nutrilife! "); jButton1.setFont(new java.awt.Font("DejaVu Sans Light", 1, 18)); jButton1.setText("NUEVO PACIENTE"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jButton2.setFont(new java.awt.Font("DejaVu Sans Light", 1, 18)); jButton2.setText("MODIFICAR PACIENTE"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jButton3.setFont(new java.awt.Font("DejaVu Sans Light", 1, 18)); jButton3.setText("BORRAR PACIENTE"); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); jButton4.setFont(new java.awt.Font("DejaVu Sans Light", 1, 18)); jButton4.setText("VER PACIENTES"); jButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton4ActionPerformed(evt); } }); jButton5.setFont(new java.awt.Font("DejaVu Sans Light", 1, 18)); jButton5.setText("NUEVA DIETA"); jButton5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton5ActionPerformed(evt); } }); jButton6.setFont(new java.awt.Font("DejaVu Sans Light", 1, 18)); jButton6.setText("MODIFICAR DIETA"); jButton6.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton6ActionPerformed(evt); } }); jButton7.setFont(new java.awt.Font("DejaVu Sans Light", 1, 18)); jButton7.setText("BORRAR DIETA"); jButton7.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton7ActionPerformed(evt); } }); jButton8.setFont(new java.awt.Font("DejaVu Sans Light", 1, 18)); jButton8.setText("VER DIETAS"); jButton8.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton8ActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel2)) .addGroup(layout.createSequentialGroup() .addGap(92, 92, 92) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(jButton2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE) .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE) .addComponent(jButton4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE) .addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(171, 171, 171) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jButton8, javax.swing.GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE) .addComponent(jButton7, javax.swing.GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE) .addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE) .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)) .addGap(61, 61, 61))) .addGap(47, 47, 47)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(34, 34, 34) .addComponent(jLabel1) .addGap(63, 63, 63)) .addGroup(layout.createSequentialGroup() .addContainerGap(129, Short.MAX_VALUE) .addComponent(jLabel2) .addGap(32, 32, 32))) .addGap(26, 26, 26) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(30, 30, 30) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(30, 30, 30) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(34, 34, 34) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(131, 131, 131)) ); pack(); }//
ppublic class Carbohidrato { double lecheDescremada; double lecheSemidescremada; double lecheEntera; double lecheConAzucar; double fruta; double verdura; double azucarSinGrasa; double azucarConGrasa; double leguminosa; double cerealSinGrasa; double cerealConGrasa; double alimentoMuyMagro; double alimentoMagro; double alimentoSemigraso; double alimentoGraso; double aceiteSinProteina; double aceiteConProteina; double subtotal1; double subtotal2; double subtotal3; double subtotal4; int intercambioLecheDescremada = 1; int intercambioLecheSemidescremada = 0; int intercambioLecheEntera = 0; int intercambioLecheConAzucar = 0; int intercambioFruta = 3; int intercambioVerdura = 3; int intercambioAzucarSinGrasa = 2; int intercambioAzucarConGrasa = 1; int intercambioLeguminosa = 3; int intercambioCerealConGrasa = 1; int intercambioCerealSinGrasa = 2; int intercambioAlimentoMuyMagro = 3; int intercambioAlimentoMagro = 1; int intercambioAlimentoSemigraso = 0; int intercambioAlimentoGraso = 0; int intercambioAceiteSinProteina = 1; int intercambioAceiteConProteina = 0; //Metodos set public void setLecheDescremada() { lecheDescremada = (intercambioLecheDescremada * 12); } public void setLecheSemidescremada() { lecheSemidescremada = (intercambioLecheSemidescremada * 12); } public void setLecheEntera() { lecheEntera = (intercambioLecheEntera * 12); } public void setLecheConAzucar() { lecheConAzucar = (intercambioLecheConAzucar * 30); } public void setFruta() { fruta = (intercambioFruta * 15); } public void setVerdura() { verdura = (intercambioVerdura * 4); } public void setAzucarSinGrasa() { azucarSinGrasa = (intercambioAzucarSinGrasa * 10); } public void setAzucarConGrasa() { azucarConGrasa = (intercambioAzucarConGrasa * 10); } public void setLeguminosa() { leguminosa = (intercambioLeguminosa * 20); } public void setCerealSinGrasa() { cerealSinGrasa = (intercambioCerealSinGrasa * 15); } public void setCerealConGrasa() { cerealConGrasa = (intercambioCerealConGrasa * 15); } public void setAlimentoMuyMagro() { alimentoMuyMagro = (intercambioAlimentoMuyMagro * 0); } public void setAlimentoMagro() { alimentoMagro = (intercambioAlimentoMagro * 0); } public void setAlimentoSemigraso() { alimentoSemigraso = (intercambioAlimentoSemigraso * 0); } public void setAlimentoGraso() { alimentoGraso = (intercambioAlimentoGraso * 0); } public void setAceiteSinProteina() { aceiteSinProteina = (intercambioAceiteSinProteina * 0); } public void setAceiteConProteina() { aceiteConProteina = (intercambioAceiteConProteina * 3); } public double setSubtotal1() { subtotal1 = ( lecheDescremada + lecheSemidescremada + lecheEntera + lecheConAzucar + fruta + verdura + azucarSinGrasa + azucarConGrasa + leguminosa ); return subtotal1; } public double setSubtotal2() { subtotal2 = ( cerealSinGrasa + cerealConGrasa); return subtotal2; } public double setSubtotal3() { subtotal3 = ( alimentoMuyMagro + alimentoMagro + alimentoSemigraso + alimentoGraso); return subtotal3; } public double setSubtotal4() { subtotal4 = ( aceiteSinProteina + aceiteConProteina); return subtotal4; } public void setClaseCarbohidrato() { setLecheDescremada(); setLecheSemidescremada(); setLecheEntera(); setLecheConAzucar(); setFruta(); setVerdura(); setAzucarSinGrasa(); setAzucarConGrasa(); setLeguminosa(); setCerealSinGrasa(); setCerealConGrasa(); setAlimentoMuyMagro(); setAlimentoMagro(); setAlimentoSemigraso(); setAlimentoGraso(); setAceiteSinProteina(); setAceiteConProteina(); double subtotal1 = setSubtotal1(); double subtotal2 = setSubtotal2(); double subtotal3 = setSubtotal3(); double subtotal4 = setSubtotal4(); } }
package proyecto; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import junit.textui.TestRunner;
public class Prueba extends TestCase { protected Carbohidrato c; protected void setUp() { this.c = new Carbohidrato(); return; } public static Test suite() { return new TestSuite(Prueba.class); }
public void test1() { double expected = 159.0; c.setClaseCarbohidrato(); double actual = c.setSubtotal1(); assertEquals(expected,actual); return; } public void test2() { double expected = 40.0; c.setClaseCarbohidrato(); double actual = c.setSubtotal2(); assertEquals(expected, actual); return; } public void test3() { double expected = 0.0; c.setClaseCarbohidrato(); double actual = c.setSubtotal3(); assertEquals(expected,actual); return; }
public void test2() { double expected = 40.0; c.setClaseCarbohidrato(); double actual = c.setSubtotal2(); assertEquals(expected, actual); return; }