Advertisement
MOISES_QUISPE_ROJAS

Estructura Datos 2021 - TP03 P06

Oct 8th, 2021
902
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.66 KB | None | 0 0
  1. /* Estructura de Datos - Facultad de Ingenieria - Universidad Nacional de Jujuy
  2.  *
  3.  * @Autor: Equipo 4.1
  4.  */
  5. /*      @integrantes:                  |    @Carrera:             |   @LU:
  6.                                        |                          |
  7.   Flores ,Cesar Ismael                 | Lic. en Sistemas         | 1782
  8.   Llampa, Ariel Angel Gabriel          | Ing. Informatica         | 8445
  9.   Machaca, Rodrigo Agustin             | Ing. Informatica         | 8512
  10.   Perez, Emanuel Ismael                | Ing. Informatica         | 8393
  11.   Quispe Rojas, Moises Esteban Nicolas | Ing. Informatica         | 7286
  12.  
  13.     Una impresora organiza los documentos que va a imprimir en su cola de impresión. En relación a cada
  14.     documento se mantiene la siguiente información: nombre, cantidad de hojas a imprimir, tamaño de papel
  15.     (A4, oficio o carta), número de copias y preferencia (color o escala de grises).
  16.     A través de un menú de opciones realizar las tareas vinculadas a la impresión de documentos:
  17.         ● Registrar la información de los documentos a imprimir y agregarlos a la cola de impresión.
  18.         ● Simular la impresión desencolando los documentos y presentando la información de los mismos
  19.         por pantalla.
  20.     Además, informar cuantos documentos se imprimieron a color, cuantos en tamaño oficio, cuál fue el
  21.     documento con mayor número de copias y cuál el de menor cantidad de hojas a imprimir.
  22.     Modifique el programa escrito de manera que permita optar entre el ingreso de valores por consola o por
  23.     un generador de valores aleatorios.
  24.  
  25. */
  26.  
  27. package Queue;
  28. import java.util.Objects;
  29.  
  30. public class ED_E6 {
  31.     private Queue<Document> queuePrint ;
  32.     private Document docx;
  33.    
  34.     public static void main(String[] args) {
  35.         (new ED_E6()).open();
  36.     }
  37.    
  38.     public void open(){
  39.         char option;
  40.         do{
  41.             do{
  42.                 System.out.println("Estructura de Datos - Ejercicio 6");
  43.                 System.out.println("(1) Registro Manual");
  44.                 System.out.println("(2) Registro Automatico");
  45.                 System.out.println("(3) Imprimir");
  46.                 option = Helper.getChar();
  47.             }while(validateOption(option));
  48.         }while(run(option));
  49.     }
  50.          
  51.     public void printDocuments(){
  52.         Integer countColor = 0,countSizeOficio = 0;
  53.         Document documentMoreCopies = null,documentFewPages = null;      
  54.         Boolean band=true;
  55.         while(!this.queuePrint.isEmpty()){
  56.             System.out.println("Imprimiendo...");  
  57.             if(this.queuePrint.peek().getColor()==preferences.COLOR){
  58.                 countColor++;
  59.             }
  60.             if(this.queuePrint.peek().getPaperSize()==paper.OFICIO){
  61.                 countSizeOficio++;
  62.             }
  63.             if(band){
  64.                documentMoreCopies=this.queuePrint.peek();
  65.                documentFewPages=this.queuePrint.peek();
  66.                band=false;
  67.             }else{
  68.                if(this.queuePrint.peek().getNumberCopies()>documentMoreCopies.getNumberCopies()){
  69.                    documentMoreCopies=this.queuePrint.peek();
  70.                }
  71.                if(this.queuePrint.peek().getNumberLeaves()<documentFewPages.getNumberLeaves()){
  72.                    documentFewPages=this.queuePrint.peek();
  73.                }
  74.             }
  75.             System.out.println(this.queuePrint.remove());
  76.         }    
  77.         System.out.println("Documentos imprimidos a color: "+countColor);
  78.         System.out.println("Documentos imprimidos en tamaño oficio: "+countSizeOficio);
  79.         System.out.println("Documento con mas copias: \n"+documentMoreCopies);
  80.         System.out.println("Documento con menor hojas: \n"+documentFewPages);
  81.     }
  82.        
  83.     public boolean run(char option){
  84.         switch(option){
  85.             case '1':
  86.                 registerManual();
  87.                 return true;
  88.             case '2':
  89.                 registerAutomatic();
  90.                 return true;
  91.             case '3':
  92.                 printDocuments();
  93.                 return false;
  94.                 default:
  95.                     return false;
  96.         }
  97.     }
  98.    
  99.     public boolean validateOption(char option){
  100.         switch(option){
  101.             case '1':
  102.                     return false;
  103.             case '2':
  104.                     return false;
  105.             case '3':
  106.                 if(Objects.isNull(this.queuePrint)){
  107.                     System.out.println("Debe primero cargar documentos");
  108.                     return true;
  109.                 }else{
  110.                     return false;
  111.                 }
  112.             default:
  113.                     System.out.println("Opcion no contemplada");
  114.                     return true;
  115.         }
  116.     }
  117.    
  118.     public void registerManual(){
  119.         String name;
  120.         int numberLeaves,numberCopies;
  121.         paper paperSize;
  122.         preferences color;
  123.         System.out.print("Ingrese la cantidad de documentos a registrar: ");
  124.         int amount=Helper.getIntegerPositive();
  125.         this.queuePrint = new Queue<>(amount);
  126.         for(int i=0;i<amount;i++){
  127.             System.out.print("Ingrese Nombre del Documento: ");
  128.             name=Helper.getString()+".docx";
  129.             System.out.print("Ingrese n° de Hojas: ");
  130.             numberLeaves=Helper.getIntegerPositive();
  131.             System.out.print("Ingrese tipo de Papel: ");
  132.             paperSize=validatePaperSize();
  133.             System.out.print("Ingrese n° de Copias: ");
  134.             numberCopies=Helper.getIntegerPositive();
  135.             System.out.print("Ingrese Preferencia (Color/Grises): ");
  136.             color= validatePreferences();          
  137.             this.docx = new Document(name,numberLeaves,paperSize,numberCopies,color);
  138.             System.out.println((i+1)==1? ((i+1)+" documento en espera..."): ((i+1)+" documentos en espera..."));
  139.             System.out.println(docx);
  140.             this.queuePrint.add(docx);
  141.         }            
  142.     }
  143.    
  144.     public preferences validatePreferences(){
  145.         boolean band = true;
  146.         String colorString;
  147.         preferences color= null;
  148.         do{
  149.             try {
  150.                 colorString=Helper.getString().toUpperCase();
  151.                 color= preferences.valueOf(colorString);
  152.                 band=false;
  153.             } catch (Exception e) {
  154.                 System.out.println("Tipo de Preferencia no aceptado");
  155.                 System.out.print("Intentelo de nuevo: ");
  156.             }
  157.         }while(band);
  158.         return color;        
  159.     }
  160.                
  161.     public paper validatePaperSize(){
  162.         boolean band = true;
  163.         String paperSizeString;
  164.         paper type = null ;
  165.         do{
  166.             try {
  167.                 paperSizeString = Helper.getString().toUpperCase();
  168.                 type = paper.valueOf(paperSizeString);
  169.                 band = false;
  170.             } catch (Exception e) {
  171.                 System.out.println("Tipo de papel no aceptado");
  172.                 System.out.print("Intentelo de nuevo: ");
  173.             }          
  174.         }while(band);
  175.         return type;
  176.     }
  177.        
  178.     public void registerAutomatic(){  
  179.         int amount = Helper.random.nextInt(10)+1;
  180.         this.queuePrint = new Queue<>(amount);
  181.         for (int i = 0; i < amount; i++) {
  182.             String name = someNames[Helper.random.nextInt(someNames.length)];
  183.             int numberLeaves = Helper.random.nextInt(10)+1;
  184.             int nRandom= Helper.random.nextInt(3);
  185.             paper paperSize = nRandom==0? paper.A4 : nRandom==1? paper.OFICIO : paper.CARTA ;
  186.             int numberCopies = Helper.random.nextInt(20);
  187.             preferences color = Helper.random.nextInt(2)==0? preferences.COLOR : preferences.GRISES;
  188.             this.docx = new Document(name, numberLeaves, paperSize, numberCopies, color);
  189.             System.out.println((i+1)==1? ((i+1)+" documento en espera..."): ((i+1)+" documentos en espera..."));
  190.             System.out.println(docx);
  191.             this.queuePrint.add(docx);
  192.         }      
  193.     }    
  194.    
  195.     private String[] someNames= {
  196.             "Foundations of Computer Science. C Edition.docx",
  197.             "Estructura de Datos y Algoritmos.docx",
  198.             "Python no Muerde Yo Sí.docx",
  199.             "Curso Python para Principiantes.docx",
  200.             "Organization and Maintenance of Large Ordered Indexes.docx",
  201.             "Algoritmos y Estructura de Datos.docx",
  202.             "Algorithmics Theory and Practice.docx",
  203.             "Fundamentals of Algorithmics.docx",
  204.             "Introduction to Algorithms.docx",
  205.             "Data Structures and Algorithms in Python.docx",
  206.             "C++ How to Progrmam Instructor's Manual Contents.docx",
  207.             "Cómo Programar en C, C++ y Java.docx",
  208.             "Cómo Programar en C#.docx",
  209.             "Java Cómo Programar.docx",
  210.             "Java How to Program.docx",
  211.             "Data Structures and Algorithms in C++.docx",
  212.             "Thinking in C++, Volume 1.docx",
  213.             "Thinking in C++, Volume 2.docx",
  214.             "Estructuras de datos en Java.docx",
  215.             "Estructura de datos en C++.docx",
  216.             "Algorithm Design.docx",
  217.             "The Art of Computer Programming Volume 1 Fundamental Algorithms 2nd Edition.docx",
  218.             "Learning Python.docx",
  219.             "Programming Python.docx",
  220.             "Introduction to Theory of Computation.docx",
  221.             "Fundamentos de Programación en Java.docx",
  222.             "Handbook of Data Structures and Applications.docx",
  223.             "Open Data Structures (in Java).docx",
  224.             "The C++ Programming Language.docx",
  225.             "Python Tutorial. Release 3.2.3.docx",
  226.             "El tutorial de Python.docx"  
  227.     };    
  228. }
  229.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement