Created
March 28, 2017 14:37
-
-
Save JDRamosC/4c09fd9a7845a3ead5e3af5378164fc9 to your computer and use it in GitHub Desktop.
Juan Daniel Ramos - Ejercicio en Clases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package bo.edo.ubi; | |
/** | |
* Created by HP-PC on 28/03/2017. | |
*/ | |
public class Documento { | |
private String nombre; | |
private String extencion; | |
private int nroHojas; | |
private String tipoImpresion; | |
public Documento(String nombre, String extencion, int nroHojas, String tipoImpresion) { | |
this.nombre = nombre; | |
this.extencion = extencion; | |
this.nroHojas = nroHojas; | |
this.tipoImpresion = tipoImpresion; | |
} | |
public Documento() { | |
this.nombre = ""; | |
this.extencion = ""; | |
this.nroHojas = 0; | |
this.tipoImpresion = ""; | |
} | |
public String getNombre() { | |
return nombre; | |
} | |
public void setNombre(String nombre) { | |
this.nombre = nombre; | |
} | |
public String getExtencion() { | |
return extencion; | |
} | |
public void setExtencion(String extencion) { | |
this.extencion = extencion; | |
} | |
public int getNroHojas() { | |
return nroHojas; | |
} | |
public void setNroHojas(int nroHojas) { | |
this.nroHojas = nroHojas; | |
} | |
public String getTipoImpresion() { | |
return tipoImpresion; | |
} | |
public void setTipoImpresion(String tipoImpresion) { | |
this.tipoImpresion = tipoImpresion; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package bo.edo.ubi; | |
import com.sun.org.apache.xpath.internal.SourceTree; | |
import java.util.ArrayDeque; | |
import java.util.ArrayList; | |
import java.util.LinkedList; | |
import java.util.Queue; | |
public class Main { | |
public static void main(String[] args) { | |
//Creamos los documentos necesarios | |
Documento d1 = new Documento("Practica", "doc", 3, "BYC"); | |
Documento d2 = new Documento("Examen", "doc", 12, "COL"); | |
Documento d3 = new Documento("Fisica", "pdf", 20, "BYC"); | |
Documento d4 = new Documento("Metodos Numericos", "doc", 12, "COL"); | |
//Creamos la cola donde iran nuestros documentos | |
Queue<Documento> colaImpresion = new LinkedList<Documento>(); | |
//Agregamos los documentos a la cola | |
colaImpresion.add(d1); | |
colaImpresion.add(d2); | |
colaImpresion.add(d3); | |
colaImpresion.add(d4); | |
//Metodo para saber q tamto de hojas se necesita para las impresiones | |
System.out.println("El total de hojas necesarias es: "+ obtenerTotalHojas(colaImpresion)); | |
//Creamos una pila adicional para que las impreseiones a color vayan a ella | |
Queue<Documento> colaImpresionColor = new LinkedList<Documento>(); | |
//Metodo para trasladar los documentos que son a color | |
trasladarDocsColor(colaImpresion, colaImpresionColor); | |
//Metodo para mostrar las colas: | |
System.out.println("Las impresiones a Blanco y Negro(BYN): "); | |
mostrar(colaImpresion); | |
System.out.println("Las impresiones a Color(COL): "); | |
mostrar(colaImpresionColor); | |
} | |
private static void mostrar(Queue<Documento> a) { | |
int n = a.size(); | |
for (int i = 0; i < n; i++) { | |
Documento x = a.remove(); | |
System.out.println(x.getNombre() + " | " + x.getExtencion() + " | " + x.getNroHojas() + " | " + x.getTipoImpresion()); | |
a.add(x); | |
} | |
} | |
private static void trasladarDocsColor(Queue<Documento> a, Queue<Documento> b) { | |
int n = a.size(); | |
for (int i = 0; i < n; i++) { | |
Documento x = a.remove(); | |
if (x.getTipoImpresion() == "BYC") { | |
a.add(x); | |
} else { | |
b.add(x); | |
} | |
} | |
} | |
private static int obtenerTotalHojas(Queue<Documento> a) { | |
int n = a.size(); | |
int totalHojas = 0; | |
for (int i = 0; i < n; i++) { | |
Documento x = a.remove(); | |
totalHojas = totalHojas + x.getNroHojas(); | |
a.add(x); | |
} | |
return totalHojas; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment