Algoritmos y Estructura de Datos - CL2
Algoritmos y Estructura de Datos - CL2
DIRECCIÓN ACADÉMICA
CARRERA PROFESIONALES
NOTA
CURSO : Algoritmos y Estructura de Datos
PROFESOR : Ing. Manuel Huertas Honores
SEMESTRE : 2023-II
SECCIÓN : T2WT
FECHA INICIO : 07/08/2023 HORA: 00:00
FECHA FIN : 10/08/2023 HORA: 23:59
ALUMNO (A) :
Consolidado
Puntaje Llenar solo en caso de Recalificación justificada
Pregunta
Máximo Obtenido Sustento Puntaje
1 08
2 04
3 04
4 04
Nota Recalificada
IESTP CIBERTEC 1
PREGUNTA 01:
Implemente la clase Docente en el paquete clase con los atributos privados: código (int), nombre
(String), horas (int) y tarifa (double); un constructor que inicialice los atributos privados, los métodos
de acceso público set/get y el método sueldo (horas * tarifa).
Implemente la clase ArregloDocentes en el paquete arreglo con el atributo privado doc (ArrayList de
tipo Docente) e implemente:
Métodos básicos
- Un constructor que cree el ArrayList y adicione las DirMem de ocho objetos Docente.
- Método adicionar que recibe la DirMem de un nuevo docente y lo adicione al ArrayList.
- Método tamaño que retorne la cantidad de objetos Docente registrados hasta ese momento.
- Método obtener que reciba una posición y retorne la DirMem del objeto Docente respectivo.
Métodos complementarios
- Retorne el sueldo promedio.
- Retorne el sueldo mayor.
- Retorne el sueldo menor.
- Retorne la tarifa mayor.
- Retorne la tarifa menor.
En la clase principal:
- Considere la declaración global ArregloDocentes ad = new ArregloDocentes();
- Implemente la pulsación del botón Adicionar que agregue un nuevo docente.
- Implemente la pulsación del botón Reportar que muestre los retornos de los métodos
complementarios.
public ArregloDocente(){
doc = new ArrayList <Docente>();
adicionar(new Docente(100,"Migue",10,14.5));
adicionar(new Docente(101,"MArtinr",18,15.5));
adicionar(new Docente(102,"Oscar",12,13.5));
adicionar(new Docente(103,"Tifany",16,17.5));
adicionar(new Docente(104,"Maria",16,15.5));
adicionar(new Docente(105,"Javier",12,15.5));
adicionar(new Docente(106,"Luis",11,19.1));
adicionar(new Docente(107,"Pedro",12,15.5));
}
IESTP CIBERTEC 2
public int tamaño(){
return doc.size();
}
IESTP CIBERTEC 3
}
return menor;
}
}
CLASE DOCENTE:
package clase;
IESTP CIBERTEC 4
public void setTarfia(double tarifa){
this.tarifa = tarifa;
}
GUI:
package gui;
import arreglo.ArregloDocente;
import clase.Docente;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
public Ejer1() {
initComponents();
modelo = new DefaultTableModel();
ad = new ArregloDocente();
listar();
}
public void listar(){
modelo = (DefaultTableModel) tblDocentes.getModel();
Object[] ob = new Object[10];
for(int i = 0; i< ad.tamaño();i++){
ob[0] = ad.obtener(i).getCodigo();
ob[1] = ad.obtener(i).getNombre();
ob[2] = ad.obtener(i).getHoras();
ob[3] = ad.obtener(i).getTarifa();
modelo.addRow(ob);
}
tblDocentes.setModel(modelo);
}
public void limpiarTabla(){
for(int i=0;i<modelo.getRowCount();i++){
modelo.removeRow(i);
i = i-1;
}
}
IESTP CIBERTEC 5
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("Adicionar");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("Reportar");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jLabel1.setText("Nombre:");
jLabel2.setText("Código:");
jLabel3.setText("Horas:");
jLabel4.setText("Tarifa:");
tblDocentes.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"Código", "Nombre", "Horas", "Tarifa"
}
){
Class[] types = new Class [] {
java.lang.Integer.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class
};
IESTP CIBERTEC 6
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
});
jScrollPane1.setViewportView(tblDocentes);
IESTP CIBERTEC 7
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(32, 32, 32)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton1)
.addGap(18, 18, 18)
.addComponent(jButton2))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jLabel4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtHoras, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtTarifa, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 174,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(41, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
ad.adicionar(new Docente(codigo,nombre,horas,tarifa));
limpiarTabla();
listar();
}
IESTP CIBERTEC 8
/* 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.
* 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(Ejer1.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Ejer1.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Ejer1.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Ejer1.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
}
//</editor-fold>
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Ejer1().setVisible(true);
}
});
}
public void listado() {
String mensaje = "Sueldo Promedio: "+ ad.sueldoPromedio()+ "\n"
+ "Sueldo mayor: " + ad.sueldoMayor()+ "\n"
+ "Sueldo menor: " + ad.sueldoMenor()+ "\n"
+ "Tarifa mayor: " + ad.tarifaMayor()+ "\n"
+ "Tarifa menor: " + ad.tarifaMenor()+ "\n";
JOptionPane.showMessageDialog(null, mensaje);
}
IESTP CIBERTEC 9
private javax.swing.JLabel jLabel4;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable tblDocentes;
private javax.swing.JTextField txtCodigo;
private javax.swing.JTextField txtHoras;
private javax.swing.JTextField txtNombre;
private javax.swing.JTextField txtTarifa;
Crea el formulario
Crea el formulario de forma
10 Puntos completamente y es No Crea el formulario
incompleta
funcional
PREGUNTA 02:
Implemente la clase Factura en el paquete clase con los atributos privados: ruc (String), empresa
(String), unidades (int) y precio unitario (double); un constructor que inicialice los atributos privados,
los métodos de acceso público set/get y el método importeFacturado (unidades * precio unitario).
Implemente la clase ArregloFacturas en el paquete arreglo con el atributo privado fac (ArrayList de
tipo Factrura) e implemente:
Métodos básicos
- Un constructor que cree el ArrayList y adicione las DirMem de ocho objetos Factura.
- Método adicionar que recibe la DirMem de una nueva factura y la adiciona al ArrayList.
- Método tamaño que retorne la cantidad de objetos Factura registrados hasta ese momento.
- Método obtener que reciba una posición y retorne la DirMem del objeto Factura respectivo.
Métodos complementarios
- Retorne suma de todos los importes facturados.
- Retorne importe promedio facturado.
- Retorne menor importe facturado.
- Retorne mayor importe facturado.
- Retorne nombre de la primera empresa cuyo importe facturado sea menor al importe promedio
facturado.
En la clase principal:
- Considere la declaración global ArregloFacturas af = new ArregloFacturas();
- Implemente la pulsación del botón Adicionar que agregue una nueva factura.
- Implemente la pulsación del botón Reportar que muestre los retornos de los métodos
complementarios.
IESTP CIBERTEC 10
El alumno genera lo El alumno genera lo solicitado
10 Puntos No resuelve lo solicitado
solicitado. de forma parcial
ARREGLO FACTURAS
package arreglo;
import clase.Factura;
import java.util.ArrayList;
public ArregloFactura(){
fac = new ArrayList <Factura>();
adicionar(new Factura("1000000020","MINA ORO AZUL",15,9.0));
adicionar(new Factura("1000000021","FERETERIA ORO",11,1.0));
adicionar(new Factura("1000000022","TRUJILLO SAC",25,5.9));
adicionar(new Factura("1000000023","YANACOCHAS",25,5.0));
adicionar(new Factura("1000000024","IMPORT ORO",17,7.0));
adicionar(new Factura("1000000025","TRUJILLO CITY",11,20.0));
adicionar(new Factura("1000000026","MOCHE SA",10,15.0));
adicionar(new Factura("1000000027","LA LIBERTAD SA",10,1.0));
return fac.size();
}
IESTP CIBERTEC 11
public double importePromedio(){
double suma = 0.0;
for(int i=0;i<tamaño();i++){
suma += obtener(i).importeFacturado();
}
return suma/tamaño();
}
if(obtener(i).importeFacturado()<importePromedio()){
emi = obtener(i).getEmpresa();
break;
}
}
return emi;
}
}
CLASE FACTURA
package clase;
IESTP CIBERTEC 12
this.empresa = empresa;
this.unidades = unidades;
this.precioUnitario = precioUnitario;
}
GUI
package gui;
import arreglo.ArregloFactura;
import clase.Factura;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
IESTP CIBERTEC 13
private ArregloFactura af ;
DefaultTableModel modelo;
/**
* Creates new form Ejer2
*/
public Ejer2() {
initComponents();
modelo = new DefaultTableModel();
af = new ArregloFactura();
listar();
}
public void listar(){
modelo = (DefaultTableModel) tblDocentes.getModel();
Object[] ob = new Object[10];
for(int i = 0; i< af.tamaño();i++){
ob[0] = af.obtener(i).getRuc();
ob[1] = af.obtener(i).getEmpresa();
ob[2] = af.obtener(i).getUnidades();
ob[3] = af.obtener(i).getPrecioUnitario();
modelo.addRow(ob);
}
tblDocentes.setModel(modelo);
}
public void limpiarTabla(){
for(int i=0;i<modelo.getRowCount();i++){
modelo.removeRow(i);
i = i-1;
}
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel3.setText("Unidades:");
IESTP CIBERTEC 14
jButton1.setText("Adicionar");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jLabel4.setText("Precio unitario:");
tblDocentes.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"RUC", "Razón Social", "Unidades", "Precio unitario"
}
){
Class[] types = new Class [] {
java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.Double.class
};
jButton2.setText("Reportar");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jLabel1.setText("Razón Social:");
jLabel2.setText("RUC:");
IESTP CIBERTEC 15
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 525,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN
G)
.addComponent(txtUnidades, javax.swing.GroupLayout.PREFERRED_SIZE, 71,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 52,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN
G)
.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 92,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtPrecioUnitario, javax.swing.GroupLayout.PREFERRED_SIZE,
82, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN
G)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 52,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtRuc, javax.swing.GroupLayout.PREFERRED_SIZE, 132,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN
G)
.addComponent(txtEmpresa, javax.swing.GroupLayout.PREFERRED_SIZE, 135,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 82,
javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(117, 117, 117)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
.addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 89,
javax.swing.GroupLayout.PREFERRED_SIZE))))
.addContainerGap(25, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(32, 32, 32)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton1)
.addGap(18, 18, 18)
.addComponent(jButton2))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
IESTP CIBERTEC 16
.addComponent(jLabel1)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtRuc, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtEmpresa, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(jLabel4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtUnidades, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtPrecioUnitario, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(26, 26, 26)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 174,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(134, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
af.adicionar(new Factura(ruc,empresa,unidades,precioUnitario));
limpiarTabla();
listar();
}
IESTP CIBERTEC 17
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Ejer2.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Ejer2.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Ejer2.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Ejer2.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
}
//</editor-fold>
JOptionPane.showMessageDialog(null, mensaje);
}
PREGUNTA 03:
IESTP CIBERTEC 18
Crea la clase notas o similares para poder calcular el promedio de notas, verificar si está aprobado y
clasificar a los alumnos de la siguiente manera:
17+ (Sobresaliente)
13 hasta 16 (regular)
13 – (por mejorar)
PREGUNTA 04:
Generar una concatenación de resultados indicando:
IESTP CIBERTEC 19