This document contains a lab guide for a Java Swing package assignment. It lists the names of 5 students assigned to the group. It also contains 3 questions/problems for the students to solve involving calculating change needed in bills and coins, calculating speed from distance and time, and summing two times formatted as hours, minutes, seconds.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
39 views
Guía de Laboratorio #06 (Poo-Paquetes Swing)
This document contains a lab guide for a Java Swing package assignment. It lists the names of 5 students assigned to the group. It also contains 3 questions/problems for the students to solve involving calculating change needed in bills and coins, calculating speed from distance and time, and summing two times formatted as hours, minutes, seconds.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12
GUÍA DE LABORATORIO N° 06 (POO-Paquetes
Swing)
Integrantes:
1. Piscoya Bances, Jesús Rafael.
2. Montenegro Granados, Alessandro. 3. Alvarado Barrientos, Michael. 4. Barzola Peña, Nicolle Jenny 5. Lozano Vivar, Juan Jesús.
Lima, 29 de septiembre del 2020.
1. Mostrar la cantidad de billetes de 100, 50, 20, 10, 5 y 1 nuevo sol que se necesitan para pagar el sueldo de un trabajador.
//dentro del JFrame }
package Pregunta6; }); public class Pregunta6 extends } javax.swing.JFrame { // Variables declaration - do not modify public Pregunta6() { private javax.swing.JButton btnCalcular; initComponents(); private javax.swing.JButton btnNuevo; } private javax.swing.JLabel jLabel1; private void private javax.swing.JLabel jLabel10; btnCalcularActionPerformed(java.awt.event. private javax.swing.JLabel jLabel11; ActionEvent evt) { private javax.swing.JLabel jLabel2; double a, b, c, d, e, f; private javax.swing.JLabel jLabel3; double x, y; private javax.swing.JLabel jLabel4; a=Double.parseDouble(txtA.getText()); private javax.swing.JLabel jLabel5; b=Double.parseDouble(txtB.getText()); private javax.swing.JLabel jLabel6; c=Double.parseDouble(txtC.getText()); private javax.swing.JLabel jLabel7; d=Double.parseDouble(txtD.getText()); private javax.swing.JLabel jLabel8; e=Double.parseDouble(txtE.getText()); private javax.swing.JLabel jLabel9; f=Double.parseDouble(txtF.getText()); private javax.swing.JTextField txtA; Pregunta06 obj=new Pregunta06(a, b, private javax.swing.JTextField txtB; c, d, e, f); private javax.swing.JTextField txtC; x=obj.getX(); private javax.swing.JTextField txtD; y=obj.getY(); private javax.swing.JTextField txtE; txtX.setText(String.valueOf(x)); private javax.swing.JTextField txtF; txtY.setText(String.valueOf(y)); private javax.swing.JLabel txtX; } private javax.swing.JLabel txtY; private void // End of variables declaration btnNuevoActionPerformed(java.awt.event.A } ctionEvent evt) { txtA.setText(""); //dentro de la clase Pregunta01 txtB.setText(""); package Pregunta1; txtC.setText(""); public class Pregunta01 { txtD.setText(""); private double sueldo; txtE.setText(""); public Pregunta01(double sueldo) { txtF.setText(""); this.sueldo = sueldo; txtX.setText(""); } txtY.setText(""); public double getSueldo() { txtA.requestFocus(); return sueldo; } } public static void main(String args[]) { public int getB100() { int b100; java.awt.EventQueue.invokeLater(new b100=(int)(getSueldo()/100); Runnable() { return b100; public void run() { } new Pregunta6().setVisible(true); public int getB50() { } int b50; b50=(int)(getSueldo()- public int getB5() { (getB100()*100))/50; int b5; return b50; b5=(int)(getSueldo()-(getB100()*100)- } (getB50()*50)-(getB20()*20)- (getB10()*10))/5; public int getB20() { return b5; int b20; } b20=(int)(getSueldo()-(getB100()*100)- (getB50()*50))/20; public int getB1() { return b20; int b1; } b1=(int)(getSueldo()-(getB100()*100)- (getB50()*50)-(getB20()*20)-(getB10()*10)- public int getB10() { (getB5()*5)); int b10; return b1; b10=(int)(getSueldo()-(getB100()*100)- } (getB50()*50)-(getB20()*20))/10; } return b10;
2. Calcular la velocidad de un auto en Km/h, ingresando la distancia recorrida en
metros y el tiempo en minutos. private void //dentro del JFrame btnCalcularActionPerformed(java.awt.event. package Pregunta2; ActionEvent evt) { public class Pregunta2 extends double metros=0, minutos=0, javax.swing.JFrame { velocidad=0; public Pregunta2() { initComponents(); metros=Double.parseDouble(txtMetros.getT } ext()); private javax.swing.JLabel jLabel4; minutos=Double.parseDouble(txtMinutos.get private javax.swing.JTextField txtMetros; Text()); private javax.swing.JTextField txtMinutos; Pregunta02 obj=new private javax.swing.JLabel txtVelocidad; Pregunta02(metros, minutos); // End of variables declaration velocidad=obj.getVelocidad(); }
txtVelocidad.setText(String.valueOf(velocida //dentro de la Clase Pregunta02
d)+" Km/h"); package Pregunta2; } public class Pregunta02 { private double metros, minutos; private void btnNuevoActionPerformed(java.awt.event.A public Pregunta02(double metros, double ctionEvent evt) { minutos) { txtMetros.setText(""); this.metros = metros; txtMinutos.setText(""); this.minutos = minutos; txtVelocidad.setText(""); } txtMetros.requestFocus(); } public double getMetros() { return metros; public static void main(String args[]) { } java.awt.EventQueue.invokeLater(new Runnable() { public double getMinutos() { public void run() { return minutos; new Pregunta2().setVisible(true); } } }); public double getVelocidad() { } double velocidad;
// Variables declaration - do not modify velocidad=(getMetros()/1000)/(getMinutos()/
private javax.swing.JButton btnCalcular; 60); private javax.swing.JButton btnNuevo; return velocidad; private javax.swing.JLabel jLabel1; } private javax.swing.JLabel jLabel2; } private javax.swing.JLabel jLabel3; 3. Diseñe un programa para sumar dos tiempos. Ambos tiempos vienen dados en el formato HH:MM:SS. La suma también debe ser expresada de la misma manera.
//dentro del JFrame
package pregunta33; public static void main(String args[]) { public class NewJFrame extends java.awt.EventQueue.invokeLater(new javax.swing.JFrame { Runnable() { public NewJFrame() { public void run() { initComponents(); new } NewJFrame().setVisible(true); } private void }); jButton1ActionPerformed(java.awt.event.Acti } onEvent evt) { int // Variables declaration - do not modify hh1,mm2,ss3,hh11,mm22,ss33,hhf,mmf,ssf; private javax.swing.JButton jButton1; hh1= new Integer(jtxt1.getText()); private javax.swing.JButton jButton2; mm2= new Integer(jtxt2.getText()); private javax.swing.JLabel jLabel1; ss3= new Integer(jtxt3.getText()); private javax.swing.JLabel jLabel10; hh11=new Integer(jtxt11.getText()); private javax.swing.JLabel jLabel11; mm22=new Integer(jtxt22.getText()); private javax.swing.JLabel jLabel2; ss33=new Integer(jtxt33.getText()); private javax.swing.JLabel jLabel3; Pregunta33 objti= new private javax.swing.JLabel jLabel4; Pregunta33(hh1,mm2,ss3,hh11,mm22,ss33) private javax.swing.JLabel jLabel5; ; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; jtxt4.setText(String.valueOf(objti.fini1())); private javax.swing.JLabel jLabel8; private javax.swing.JTextField jtxt1; jtxt5.setText(String.valueOf(objti.fini2())); private javax.swing.JTextField jtxt11; private javax.swing.JTextField jtxt2; jtxt6.setText(String.valueOf(objti.fini3())); private javax.swing.JTextField jtxt22; } private javax.swing.JTextField jtxt3; private javax.swing.JTextField jtxt33; private void private javax.swing.JTextField jtxt4; jButton2ActionPerformed(java.awt.event.Acti private javax.swing.JTextField jtxt5; onEvent evt) { private javax.swing.JTextField jtxt6; jtxt1.setText(""); // End of variables declaration jtxt2.setText(""); jtxt3.setText(""); //dentro de la Clase Pregunta33 jtxt11.setText(""); package pregunta33; jtxt22.setText(""); public class Pregunta33 { jtxt33.setText(""); private int t1,t2,t3,tt1,tt2,tt3; jtxt4.setText(""); public Pregunta33(int t1, int t2, int t3, int jtxt5.setText(""); tt1, int tt2, int tt3) { jtxt6.setText(""); this.t1 = t1; } this.t2 = t2; this.t3 = t3; mmf=mmf-60; this.tt1 = tt1; hhf=hhf+1; this.tt2 = tt2; }else{ this.tt3 = tt3; mmf=mmf-120; } hhf=hhf+2; } public int getT1() { if(hhf<24){ return t1; hhf=hhf; } }else if(hhf<48){ hhf=hhf-24; public int getT2() { }else{ return t2; hhf=hhf-48; } } return hhf; public int getT3() { } return t3; } int fini2(){ int ssf,mmf; public int getTt1() { mmf=getT2()+getTt2(); return tt1; ssf=ssf=getT3()+getTt3(); } if(ssf<60){ ssf=ssf; public int getTt2() { }else if(ssf<120){ return tt2; ssf=ssf-60; } mmf=mmf+1; }else{ public int getTt3() { ssf=ssf-120; return tt3; mmf=mmf+2; } } if(mmf<60){ int fini1(){ mmf=mmf; int ssf,mmf,hhf; }else if(mmf<120){ hhf=getT1()+getTt1(); mmf=mmf-60; mmf=getT2()+getTt2(); }else{ ssf=ssf=getT3()+getTt3(); mmf=mmf-120; if(ssf<60){ } ssf=ssf; return mmf; }else if(ssf<120){ } ssf=ssf-60; mmf=mmf+1; int fini3(){ }else{ int ssf,mmf; ssf=ssf-120; mmf=getT2()+getTt2(); mmf=mmf+2; ssf=ssf=getT3()+getTt3(); } if(ssf<60){ if(mmf<60){ ssf=ssf; mmf=mmf; }else if(ssf<120){ }else if(mmf<120){ ssf=ssf-60; mmf=mmf+1; } }else{ return ssf; ssf=ssf-120; } mmf=mmf+2; }
4. Dado un número natural de 4 cifras diseñe un programa que permita obtener
el revés del número. Así, si se lee el número 2358 el algoritmo deberá imprimir 8532.
//dentro del JFrame private void
package Pregunta4; jbtnCalcularActionPerformed(java.awt.event. public class jfrmEjercicio04 extends ActionEvent evt) { javax.swing.JFrame { // TODO add your handling code here: public jfrmEjercicio04() { int numero; initComponents(); String x; } numero=Integer.parseInt(jtxtNumero.getText private void ()); jbtnNuevoActionPerformed(java.awt.event.A Ejercicio04 obj=new ctionEvent evt) { Ejercicio04(numero); // TODO add your handling code here: x=obj.getCa(); jLabel4.setText(""); jLabel4.setText(String.valueOf(x)); jLabel4.requestFocus(); } } public static void main(String args[]) { private void java.awt.EventQueue.invokeLater(new jbtnCerrarActionPerformed(java.awt.event.A Runnable() { ctionEvent evt) { public void run() { // TODO add your handling code here: new System.exit(0); jfrmEjercicio04().setVisible(true); } } }); } public int getC1(){ // Variables declaration - do not modify int C1; private javax.swing.JLabel jLabel1; C1=getNumero() % 10; private javax.swing.JLabel jLabel2; return C1; private javax.swing.JLabel jLabel3; } private javax.swing.JLabel jLabel4; private javax.swing.JButton jbtnCalcular; public int getC2(){ private javax.swing.JButton jbtnCerrar; int C2; private javax.swing.JButton jbtnNuevo; C2=getNumero() % 100/10; private javax.swing.JTextField return C2; jtxtNumero; } // End of variables declaration public int getC3(){ } int C3; C3=getNumero() % 1000/100; //dentro de la Clase Ejercicio04 return C3; package ejercicio; } public class Ejercicio04 { public int getC4(){ int C4; private int numero; C4=getNumero() % 10000/1000; return C4; public Ejercicio04(int numero) { } this.numero = numero; } public String getCa(){ String c1,c2,c3,c4,reves; public Ejercicio04() { c1=String.valueOf(getC1()); } c2=String.valueOf(getC2()); c3=String.valueOf(getC3()); public int getNumero() { c4=String.valueOf(getC4()); return numero; } reves=c1+c2+c3+c4; return reves; public void setNumero(int numero) { } this.numero = numero; } } 5. Una persona tiene 2 recipientes llenos de gasolina cuyas capacidades están dadas en galones y pies cúbicos, respectivamente. Diseñe un programa que determine la cantidad total de gasolina en metros cúbicos, pies cúbicos y yardas cúbicas. Considere los siguientes factores de conversión: • 1 pie cúbico = 0.0283 metros cúbicos. • 1 galón = 3.79 litros. • 1 metro cúbico = 1000 litros. • 1 yarda cúbica = 27 pies cúbicos.
//dentro del JFrame
package ejerc_05; java.awt.EventQueue.invokeLater(new public class EJERC05 extends Runnable() { javax.swing.JFrame { public void run() { public EJERC05() { new EJERC05().setVisible(true); initComponents(); } } }); } private void jbtnconvertirActionPerformed(java.awt.event // Variables declaration - do not modify .ActionEvent evt) { private javax.swing.JLabel jLabel1; int rp1, rp2; private javax.swing.JLabel jLabel11; double m, p, y; private javax.swing.JLabel jLabel2; rp1 = Integer.parseInt(jtext1.getText()); private javax.swing.JLabel jLabel3; rp2 = Integer.parseInt(jtext2.getText()); private javax.swing.JLabel jLabel4; //proceso private javax.swing.JLabel jLabel5; conversion obj = new conversion(rp1, private javax.swing.JLabel jLabel6; rp2); private javax.swing.JLabel jLabel7; m = obj.getConversionMetro(); private javax.swing.JLabel jLabel8; p = obj.getConversionPies(); private javax.swing.JButton jbtn2; y = obj.getConversionYardas(); private javax.swing.JButton jbtnconvertir; jLabel6.setText(String.valueOf(m)); private javax.swing.JTextField jtext1; jLabel7.setText(String.valueOf(p)); private javax.swing.JTextField jtext2; jLabel8.setText(String.valueOf(y)); // End of variables declaration } }
private void //dentro de la clase Conversión
jbtn2ActionPerformed(java.awt.event.Action package ejerc_05; Event evt) { public class conversion { jtext1.setText(""); int rp1,rp2; jtext2.setText(""); jLabel6.setText(""); public conversion(int rp1, int rp2) { jLabel7.setText(""); this.rp1 = rp1; jLabel8.setText(""); this.rp2 = rp2; } }
public static void main(String args[]) { public int getRp1() {
return rp1; } double getConversionPies(){ public int getRp2() { double p=(getRp1()/7.481)+getRp2(); return rp2; return p; } }