Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Estructura de Datos - Facultad de Ingenieria - Universidad Nacional de Jujuy
- *
- * @Autor: Equipo 4.1
- */
- /* @integrantes: | @Carrera: | @LU:
- | |
- Flores ,Cesar Ismael | Lic. en Sistemas | 1782
- Llampa, Ariel Angel Gabriel | Ing. Informatica | 8445
- Machaca, Rodrigo Agustin | Ing. Informatica | 8512
- Perez, Emanuel Ismael | Ing. Informatica | 8393
- Quispe Rojas, Moises Esteban Nicolas | Ing. Informatica | 7286
- Una impresora organiza los documentos que va a imprimir en su cola de impresión. En relación a cada
- documento se mantiene la siguiente información: nombre, cantidad de hojas a imprimir, tamaño de papel
- (A4, oficio o carta), número de copias y preferencia (color o escala de grises).
- A través de un menú de opciones realizar las tareas vinculadas a la impresión de documentos:
- ● Registrar la información de los documentos a imprimir y agregarlos a la cola de impresión.
- ● Simular la impresión desencolando los documentos y presentando la información de los mismos
- por pantalla.
- Además, informar cuantos documentos se imprimieron a color, cuantos en tamaño oficio, cuál fue el
- documento con mayor número de copias y cuál el de menor cantidad de hojas a imprimir.
- Modifique el programa escrito de manera que permita optar entre el ingreso de valores por consola o por
- un generador de valores aleatorios.
- */
- package Queue;
- import java.util.Objects;
- public class ED_E6 {
- private Queue<Document> queuePrint ;
- private Document docx;
- public static void main(String[] args) {
- (new ED_E6()).open();
- }
- public void open(){
- char option;
- do{
- do{
- System.out.println("Estructura de Datos - Ejercicio 6");
- System.out.println("(1) Registro Manual");
- System.out.println("(2) Registro Automatico");
- System.out.println("(3) Imprimir");
- option = Helper.getChar();
- }while(validateOption(option));
- }while(run(option));
- }
- public void printDocuments(){
- Integer countColor = 0,countSizeOficio = 0;
- Document documentMoreCopies = null,documentFewPages = null;
- Boolean band=true;
- while(!this.queuePrint.isEmpty()){
- System.out.println("Imprimiendo...");
- if(this.queuePrint.peek().getColor()==preferences.COLOR){
- countColor++;
- }
- if(this.queuePrint.peek().getPaperSize()==paper.OFICIO){
- countSizeOficio++;
- }
- if(band){
- documentMoreCopies=this.queuePrint.peek();
- documentFewPages=this.queuePrint.peek();
- band=false;
- }else{
- if(this.queuePrint.peek().getNumberCopies()>documentMoreCopies.getNumberCopies()){
- documentMoreCopies=this.queuePrint.peek();
- }
- if(this.queuePrint.peek().getNumberLeaves()<documentFewPages.getNumberLeaves()){
- documentFewPages=this.queuePrint.peek();
- }
- }
- System.out.println(this.queuePrint.remove());
- }
- System.out.println("Documentos imprimidos a color: "+countColor);
- System.out.println("Documentos imprimidos en tamaño oficio: "+countSizeOficio);
- System.out.println("Documento con mas copias: \n"+documentMoreCopies);
- System.out.println("Documento con menor hojas: \n"+documentFewPages);
- }
- public boolean run(char option){
- switch(option){
- case '1':
- registerManual();
- return true;
- case '2':
- registerAutomatic();
- return true;
- case '3':
- printDocuments();
- return false;
- default:
- return false;
- }
- }
- public boolean validateOption(char option){
- switch(option){
- case '1':
- return false;
- case '2':
- return false;
- case '3':
- if(Objects.isNull(this.queuePrint)){
- System.out.println("Debe primero cargar documentos");
- return true;
- }else{
- return false;
- }
- default:
- System.out.println("Opcion no contemplada");
- return true;
- }
- }
- public void registerManual(){
- String name;
- int numberLeaves,numberCopies;
- paper paperSize;
- preferences color;
- System.out.print("Ingrese la cantidad de documentos a registrar: ");
- int amount=Helper.getIntegerPositive();
- this.queuePrint = new Queue<>(amount);
- for(int i=0;i<amount;i++){
- System.out.print("Ingrese Nombre del Documento: ");
- name=Helper.getString()+".docx";
- System.out.print("Ingrese n° de Hojas: ");
- numberLeaves=Helper.getIntegerPositive();
- System.out.print("Ingrese tipo de Papel: ");
- paperSize=validatePaperSize();
- System.out.print("Ingrese n° de Copias: ");
- numberCopies=Helper.getIntegerPositive();
- System.out.print("Ingrese Preferencia (Color/Grises): ");
- color= validatePreferences();
- this.docx = new Document(name,numberLeaves,paperSize,numberCopies,color);
- System.out.println((i+1)==1? ((i+1)+" documento en espera..."): ((i+1)+" documentos en espera..."));
- System.out.println(docx);
- this.queuePrint.add(docx);
- }
- }
- public preferences validatePreferences(){
- boolean band = true;
- String colorString;
- preferences color= null;
- do{
- try {
- colorString=Helper.getString().toUpperCase();
- color= preferences.valueOf(colorString);
- band=false;
- } catch (Exception e) {
- System.out.println("Tipo de Preferencia no aceptado");
- System.out.print("Intentelo de nuevo: ");
- }
- }while(band);
- return color;
- }
- public paper validatePaperSize(){
- boolean band = true;
- String paperSizeString;
- paper type = null ;
- do{
- try {
- paperSizeString = Helper.getString().toUpperCase();
- type = paper.valueOf(paperSizeString);
- band = false;
- } catch (Exception e) {
- System.out.println("Tipo de papel no aceptado");
- System.out.print("Intentelo de nuevo: ");
- }
- }while(band);
- return type;
- }
- public void registerAutomatic(){
- int amount = Helper.random.nextInt(10)+1;
- this.queuePrint = new Queue<>(amount);
- for (int i = 0; i < amount; i++) {
- String name = someNames[Helper.random.nextInt(someNames.length)];
- int numberLeaves = Helper.random.nextInt(10)+1;
- int nRandom= Helper.random.nextInt(3);
- paper paperSize = nRandom==0? paper.A4 : nRandom==1? paper.OFICIO : paper.CARTA ;
- int numberCopies = Helper.random.nextInt(20);
- preferences color = Helper.random.nextInt(2)==0? preferences.COLOR : preferences.GRISES;
- this.docx = new Document(name, numberLeaves, paperSize, numberCopies, color);
- System.out.println((i+1)==1? ((i+1)+" documento en espera..."): ((i+1)+" documentos en espera..."));
- System.out.println(docx);
- this.queuePrint.add(docx);
- }
- }
- private String[] someNames= {
- "Foundations of Computer Science. C Edition.docx",
- "Estructura de Datos y Algoritmos.docx",
- "Python no Muerde Yo Sí.docx",
- "Curso Python para Principiantes.docx",
- "Organization and Maintenance of Large Ordered Indexes.docx",
- "Algoritmos y Estructura de Datos.docx",
- "Algorithmics Theory and Practice.docx",
- "Fundamentals of Algorithmics.docx",
- "Introduction to Algorithms.docx",
- "Data Structures and Algorithms in Python.docx",
- "C++ How to Progrmam Instructor's Manual Contents.docx",
- "Cómo Programar en C, C++ y Java.docx",
- "Cómo Programar en C#.docx",
- "Java Cómo Programar.docx",
- "Java How to Program.docx",
- "Data Structures and Algorithms in C++.docx",
- "Thinking in C++, Volume 1.docx",
- "Thinking in C++, Volume 2.docx",
- "Estructuras de datos en Java.docx",
- "Estructura de datos en C++.docx",
- "Algorithm Design.docx",
- "The Art of Computer Programming Volume 1 Fundamental Algorithms 2nd Edition.docx",
- "Learning Python.docx",
- "Programming Python.docx",
- "Introduction to Theory of Computation.docx",
- "Fundamentos de Programación en Java.docx",
- "Handbook of Data Structures and Applications.docx",
- "Open Data Structures (in Java).docx",
- "The C++ Programming Language.docx",
- "Python Tutorial. Release 3.2.3.docx",
- "El tutorial de Python.docx"
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement