Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package punto;
- import java.util.LinkedList;
- import java.util.Queue;
- public class PuntoSeis {
- public static void main(String[] args) {
- new PuntoSeis().run();
- }
- void run()
- {
- Queue<Document> documents = new LinkedList<Document>();
- while(true)
- {
- int op = Helper.forceReadRangeInteger("Elija opción:\n1-Registrar información de documentos\n2-Simular impresión.", 1, 2);
- if(op == 1) registerDocuments(documents);
- else simulatePrinting(documents);
- if(!Helper.continueInput("¿Continuará la ejecución? (S/N)"));
- }
- }
- void simulatePrinting(Queue<Document> documents)
- {
- if(documents.isEmpty()) System.out.println("La cola de impresión está vacía.");
- while(!documents.isEmpty())
- {
- System.out.println(documents.poll().toString());
- }
- }
- void registerDocuments(Queue<Document> documents)
- {
- boolean random = Helper.isRandom();
- String[] optionsSize = {"A4", "Oficio", "Carta"};
- String[] preferences = {"Color", "Escala de grises"};
- while(true)
- {
- Document addDocument;
- if(random)
- {
- String name = Helper.generateRandomString();
- String size = optionsSize[Helper.getRandomIntBetweenRange(0,2)];
- int sheets = Helper.getRandomIntBetweenRange(1, 100);
- int copies = Helper.getRandomIntBetweenRange(1, 100);
- String preference = preferences[Helper.getRandomIntBetweenRange(0, 1)];
- addDocument = new Document(name,sheets,size,copies,preference);
- System.out.println("Documento generado: \n" + addDocument.toString());
- }
- else
- {
- System.out.println("Introduzca el nombre del documento:");
- String name = Helper.scanner.next();
- String size = optionsSize[Helper.forceReadRangeInteger("¿Tamaño de hoja? 1-A4\t2-Oficio\t3-Carta", 1, 3)-1];
- int sheets = Helper.forceReadPositiveInteger("¿Cuantas hojas imprimirá?");
- int copies = Helper.forceReadPositiveInteger("¿Cuantas copias imprimirá?");
- String preference = preferences[Helper.forceReadRangeInteger("¿Preferencia? 1-Color\t2-Escala de grises", 1, 2)-1];
- addDocument = new Document(name,sheets,size,copies,preference);
- }
- documents.offer(addDocument);
- if(!Helper.continueInput("¿Continuará cargando documentos? (S/N)")) return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement