Advertisement
WallHero

TP03E06MaiNClass

Oct 16th, 2020
2,457
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.24 KB | None | 0 0
  1. package punto;
  2. import java.util.LinkedList;
  3. import java.util.Queue;
  4. public class PuntoSeis {
  5.  
  6.     public static void main(String[] args) {
  7.         new PuntoSeis().run();
  8.     }
  9.    
  10.     void run()
  11.     {
  12.         Queue<Document> documents = new LinkedList<Document>();
  13.         while(true)
  14.         {
  15.             int op = Helper.forceReadRangeInteger("Elija opción:\n1-Registrar información de documentos\n2-Simular impresión.", 1, 2);
  16.             if(op == 1) registerDocuments(documents);
  17.             else simulatePrinting(documents);
  18.             if(!Helper.continueInput("¿Continuará la ejecución? (S/N)"));
  19.         }
  20.        
  21.     }
  22.    
  23.    
  24.     void simulatePrinting(Queue<Document> documents)
  25.     {
  26.         if(documents.isEmpty()) System.out.println("La cola de impresión está vacía.");
  27.         while(!documents.isEmpty())
  28.         {
  29.             System.out.println(documents.poll().toString());
  30.         }
  31.     }
  32.    
  33.     void registerDocuments(Queue<Document> documents)
  34.     {
  35.         boolean random = Helper.isRandom();
  36.         String[] optionsSize = {"A4", "Oficio", "Carta"};
  37.         String[] preferences = {"Color", "Escala de grises"};
  38.         while(true)
  39.         {
  40.             Document addDocument;
  41.             if(random)
  42.             {
  43.                 String name = Helper.generateRandomString();
  44.                 String size = optionsSize[Helper.getRandomIntBetweenRange(0,2)];
  45.                 int sheets = Helper.getRandomIntBetweenRange(1, 100);
  46.                 int copies = Helper.getRandomIntBetweenRange(1, 100);              
  47.                 String preference = preferences[Helper.getRandomIntBetweenRange(0, 1)];
  48.                 addDocument = new Document(name,sheets,size,copies,preference);
  49.                 System.out.println("Documento generado: \n" + addDocument.toString());
  50.             }
  51.             else
  52.             {
  53.                 System.out.println("Introduzca el nombre del documento:");
  54.                 String name = Helper.scanner.next();
  55.                 String size = optionsSize[Helper.forceReadRangeInteger("¿Tamaño de hoja? 1-A4\t2-Oficio\t3-Carta", 1, 3)-1];
  56.                 int sheets = Helper.forceReadPositiveInteger("¿Cuantas hojas imprimirá?");
  57.                 int copies = Helper.forceReadPositiveInteger("¿Cuantas copias imprimirá?");              
  58.                 String preference = preferences[Helper.forceReadRangeInteger("¿Preferencia? 1-Color\t2-Escala de grises", 1, 2)-1];
  59.                 addDocument = new Document(name,sheets,size,copies,preference);
  60.             }
  61.             documents.offer(addDocument);
  62.             if(!Helper.continueInput("¿Continuará cargando documentos? (S/N)")) return;
  63.         }
  64.     }
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement