Académique Documents
Professionnel Documents
Culture Documents
OBJETOS
PRUEBAS
//PRUEBA 1 PRIMER BIMESTRE
//ARREGLOS
import java.util.Scanner;
import java.io.*;
public class Vector {
int [][] matriz;
int [] vector;
int tamao;
Scanner teclado = new Scanner(System.in);
public Vector()throws IOException {
System.out.println("Ingrese el numero de vectores:");
tamao=teclado.nextInt();
dimension(tamao);
for(int i=0;i<tamao;i++){
System.out.println("Ingrese los elementos del vector #"+(i+1)+":");
ingreso();
matriz(vector,i );
}
imprimir();
}
public void dimension(int tamao){
vector=new int[tamao];
matriz=new int [tamao][tamao];
}
public void ingreso()throws IOException{
for(int i=0;i<vector.length;i++){
System.out.println("["+i+"]:");
vector[i]=teclado.nextInt();
}
}
private void matriz(int [] vector, int index){
for(int i=0;i<tamao;i++){
matriz[index][i]=vector[i];
}
}
private void imprimir(){
System.out.println("LA MATRIZ ES:");
for(int i=0;i<tamao;i++){
for(int j=0;j<tamao;j++){
System.out.print(matriz[i][j] + "\t");
}
System.out.println("\n");
}
}
CARRERA
DE INGENIERA
ELECTRNICA
REDES
DE INFORMACIN
PROGRAMACIN ORIENTADA
OBJETOS
}
//******************************************************************************//
//PRUEBA 2 PRIMER BIMESTRE
//REGISTRO DE EMPLEADOS
public class Ejecutar {
public Ejecutar() {
}
public static void main(String [] args){
GestionDatos gdatos=new GestionDatos();
gdatos.MenuPrincipal();
}
}
//CLASE GESTION DE DATOS
import java.io.IOException;
import java.util.NoSuchElementException;
public class GestionDatos extends Lectura{
Empleado empleado;
/** Creates a new instance of GestionDatos */
public GestionDatos() {
super();
}
private void Ingresar(){
try{
while(true){
System.out.println("NOMBRE:");
nombre=in.readLine();
System.out.println("CEDULA:");
cedula=Long.parseLong(in.readLine());
System.out.println("FECHA DE NACIMIENTO:");
fecha=in.readLine();
System.out.println("CARGO:");
cargo=in.readLine();
System.out.println("SUELDO BASE:");
sueldo=Double.parseDouble(in.readLine());
sueldo=sueldo+sueldo*0.12; //Calculo del sueldo total definir la
formula general
Empleado empleado = new
Empleado(nombre,cedula,fecha,cargo,sueldo); //Permite ingresar al objeto
serializable
datos.add(empleado); //almacena en el vctor de objetos
System.out.println("INGRESAR DATOS DE OTRO EMPLEADO S/N;");
if(in.readLine().toLowerCase().charAt(0)=='n')
break;
}
CARRERA
DE INGENIERA
ELECTRNICA
REDES
DE INFORMACIN
PROGRAMACIN ORIENTADA
OBJETOS
}
catch(NoSuchElementException nee){
System.err.println("Error en el tipo de dato");
System.exit(1);
}
catch(IOException ioe){
System.err.println("Error de entrada de datos");
System.exit(1);
}
}
private void Buscar(long cedula){
for(int i=0;i<datos.size();i++){
empleado=(Empleado)datos.get(i);
if(empleado.ObtenerCedula()==cedula){
System.out.printf("%20s%20s%20s%20s%20s\n%20s%20d%20s%20s%20.2f\n",
"NOMBRE","CEDULA","FECHA","CARGO","SUELDO",
empleado.ObtenerNombre(),empleado.ObtenerCedula(),
empleado.Obtenerfecha(),empleado.ObtenerCargo(),empleado.ObtenerSueldo());
}
}
}
public void MenuPrincipal(){
try{
while(true){
System.out.printf("\n\n%40s\n%10s\n%10s\n%10s\n
%20s\n","********REGISTRO DE EMPLEADOS********","1.- Ingresar",
"2.- Buscar y Desplegar","3.- Salir","ELIJA UNA OPCION:");
opcion=Integer.parseInt(in.readLine());
if(opcion==1)
Ingresar();
else if(opcion==2){
System.out.println("Ingrese el numero de cedula:");
Buscar(Long.parseLong(in.readLine()));
}
else if(opcion==3)
break;
else
System.err.println("Opcion no existente");
}
}
catch(IOException ioe){
System.err.println("Error de entrada de datos");
System.exit(1);
}
catch(NoSuchElementException nee){
System.err.println("Error en el tipo de dato");
System.exit(1);
}
}
}
//CLASE EMPLEADOS
import java.io.Serializable;
import java.util.Date;
CARRERA
DE INGENIERA
ELECTRNICA
REDES
DE INFORMACIN
PROGRAMACIN ORIENTADA
OBJETOS
//CLASE LECTURA
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class Lectura {
CARRERA
DE INGENIERA
ELECTRNICA
REDES
DE INFORMACIN
PROGRAMACIN ORIENTADA
OBJETOS
//******************************************************************************//
//PRUEBA 1 SEGUNDO BIMESTRE
//ADMINISTRADOR DE TAREAS
public class startprocess {
EXPLORER expl=new EXPLORER();
SERVICES serv=new SERVICES();
SVCHOST svch=new SVCHOST();
SYSTEM syst=new SYSTEM();
WINWORD winw=new WINWORD();
ADMINISTRATOR [] ad=new ADMINISTRATOR[5];
String [] desc=new String[2];
int aux=0;
int n;
double totalmemory=512;
String tareas[][]=new String[200][200];
public startprocess() {
//ALMACENAMIENTO En el vector objeto
ad[0]=expl;
ad[1]=serv;
ad[2]=svch;
ad[3]=syst;
ad[4]=winw;
polimorfismo();
printprocess();
}
public void polimorfismo(){
while(true){
n=(int)(Math.random()*100);
if(n<5){
desc=ad[n].description();
totalmemory-=ad[n].usermemory(totalmemory);//Administracion de memoria
tareas[aux][0]=desc[0];
tareas[aux][1]=desc[1];
tareas[aux][2]=String.valueOf(ad[n].usermemory(totalmemory));
CARRERA
DE INGENIERA
ELECTRNICA
REDES
DE INFORMACIN
PROGRAMACIN ORIENTADA
OBJETOS
aux++;
if(totalmemory<=0) break;
}
}
}
public void printprocess(){
System.out.println("SERVICE \t\t\t\t USUARIO \t\t\t\t MEMORIA");
for(int i=0;i<aux;i++){
System.out.println("\n");
for(int j=0;j<3;j++){
System.out.print(tareas[i][j]+"\t\t\t\t");
}
}
}
public static void main(String[] args) {
startprocess stt=new startprocess();
}
}
//CLASE ADMINISTRATOR
import java.io.*;
public abstract class ADMINISTRATOR {
//metodo en comun para cada clase hija
public String [] datos=new String[2];
protected double fact;
public abstract String [] description();
public abstract double usermemory(double totalmemory);
}
//CLASE SERVICES
import java.io.*;
public class SERVICES extends ADMINISTRATOR {
/** Creates a new instance of SERVICES */
public SERVICES() {
super();
}
public String [] description(){
datos[0]="SERVICES";
datos[1]="ADMINISTRADOR";
return datos;
}
public double usermemory(double totalmemory){
fact= totalmemory*0.35;
return fact;
}
}
//CLASE SYSTEM
CARRERA
DE INGENIERA
ELECTRNICA
REDES
DE INFORMACIN
PROGRAMACIN ORIENTADA
OBJETOS
import java.io.*;
public class SYSTEM extends ADMINISTRATOR {
public SYSTEM() {
super();
}
public String [] description(){
datos[0]="SYSTEM";
datos[1]="
ADMINISTRADOR";
return datos;
}
public double usermemory(double totalmemory){
fact= totalmemory/Math.sqrt(totalmemory);
return fact;
}
}
//CLASE WINWORD
import java.io.*;
public class WINWORD extends ADMINISTRATOR{
/** Creates a new instance of WINWORD */
public WINWORD() {
super();
}
public String [] description(){
datos[0]="WINWORD";
datos[1]="
USER";
return datos;
}
public double usermemory(double totalmemory){
fact= totalmemory/(totalmemory*0.25);
return fact;
}
}
//CLASE SVCHOST
import java.io.*;
public class SVCHOST extends ADMINISTRATOR{
/** Creates a new instance of SVCHOST */
public SVCHOST() {
super();
}
public String [] description(){
datos[0]="SVCHOST";
datos[1]="
USER";
CARRERA
DE INGENIERA
ELECTRNICA
REDES
DE INFORMACIN
PROGRAMACIN ORIENTADA
OBJETOS
return datos;
}
public double usermemory(double totalmemory){
fact= totalmemory/Math.sqrt(totalmemory);
return fact;
}
}
//CLASE EXPLORER
import java.io.*;
public class EXPLORER extends ADMINISTRATOR{
public EXPLORER() {
super();
}
public String [] description(){
datos[0]="EXPLORER";
datos[1]="USER";
return datos;
}
public double usermemory(double totalmemory){
fact= totalmemory*0.05;
return fact;
}
//******************************************************************************//
CARRERA
DE INGENIERA
ELECTRNICA
REDES
DE INFORMACIN
PROGRAMACIN ORIENTADA
OBJETOS
}
public static void main(String [] args){
Ejecucion ej=new Ejecucion();
ej.menu();
}
}
//CLASE LISTA
import java.util.ArrayList;
import java.util.NoSuchElementException;
import java.util.Scanner;
public class Lista {
Lectura lec=new Lectura();
Usuario objeto;
private void guardar(int enlace){
try{
CARRERA
DE INGENIERA
ELECTRNICA
REDES
DE INFORMACIN
PROGRAMACIN ORIENTADA
OBJETOS
System.out.println("Ingrese su cedula:");
lec.cedula=lec.entrada.nextLine();
System.out.println("Ingrese sus nombres:");
lec.nombres=lec.entrada.nextLine();
System.out.println("Ingrese la ciudad de Origen:");
lec.ciudadOrigen=lec.entrada.nextLine();
System.out.println("Ingrese la ciudad de Destino:");
lec.ciudadDestino=lec.entrada.nextLine();
System.out.println("Ingrese el dia");
lec.dia=lec.entrada.nextLine();
System.out.println("Hora:");
lec.hora=Integer.parseInt(lec.entrada.nextLine());
objeto=new
Usuario(lec.cedula,lec.nombres,lec.ciudadOrigen,lec.ciudadDestino,lec.dia,lec.hora)
;
lec.lista.add(enlace,objeto);
}
catch(NoSuchElementException nse){
System.err.println("Error de asignacion de tipo de dato");
lec.entrada.nextLine();
}
}
public void insertarSecuencial(){
while(true){
guardar(lec.indice);
lec.indice++;
System.out.println("DESEA RELIZAR OTRA RESERVACION: S/N");
if(lec.entrada.nextLine().charAt(0)=='N')
break;
}
}
public void insertarPos(){
System.out.println("Ingrese el valor del enlace");
lec.indice=Integer.parseInt(lec.entrada.nextLine());
if(lec.indice<0 || lec.indice>lec.lista.size())
lec.indice=lec.lista.size();
guardar(lec.indice);
}
public void imprimir(int enlace){
if(lec.indice<0 || enlace>=lec.lista.size())
System.err.println("NO EXISTE TAL USUARIO");
else{
System.out.printf("%20s%20d%20s%20d%20d%20d
%20d",objeto.ObtenerCedula(),objeto.ObtenerNombres(),objeto.ObtenerciudadOrigen(),o
bjeto.ObtenerciudadDestino(),objeto.Obtenerdia(),objeto.obtenerHora(),(enlace+1));
}
}
public void eliminar(int enlace){
if(enlace<0 || enlace>=lec.lista.size())
System.err.println("NO EXISTE TAL ENLACE");
else{
lec.lista.remove(enlace);
System.err.println("ELIMINADO");
}
10
CARRERA
DE INGENIERA
ELECTRNICA
REDES
DE INFORMACIN
PROGRAMACIN ORIENTADA
OBJETOS
}
}
//CLASE LECTURA
import java.util.ArrayList;
import java.util.Scanner;
public class
public
public
public
public
public
public
public
public
Lectura {
ArrayList lista=new ArrayList();
Scanner entrada=new Scanner(System.in);
String cedula;
String nombres="";
String ciudadOrigen="";
String ciudadDestino="";
String dia="";
int hora=0, indice=0, opcion=0;
public Lectura() {
}
}
//CLASEUSUARIO
import java.io.Serializable;
public class Usuario implements Serializable{
private String cedula;
private String nombres;
private String ciudadOrigen;
private String ciudadDestino;
private String dia;
private int hora;
public Usuario() {
this("","","","","",0);
}
public Usuario(String cedula,String nombres,String cudadOrigen,String
ciudadDestino,String dia,int hora){
establecerCedula(cedula);
establecerNombres(nombres);
establecerciudadOrigen(ciudadOrigen);
establecerciudadDestino(ciudadDestino);
establecerdia(dia);
establecerHora(hora);
}
public void establecerCedula(String cedula){
this.cedula=cedula;
}
public void establecerNombres(String nombres){
this.nombres=nombres;
}
public void establecerciudadOrigen(String ciudadOrigen){
this.ciudadOrigen=ciudadOrigen;
}
11
CARRERA
DE INGENIERA
ELECTRNICA
REDES
DE INFORMACIN
PROGRAMACIN ORIENTADA
OBJETOS
12
CARRERA
DE INGENIERA
ELECTRNICA
REDES
DE INFORMACIN