Created
March 30, 2017 22:31
-
-
Save JDRamosC/3119035171078f9d681a404554686c07 to your computer and use it in GitHub Desktop.
Juan Daniel Ramos - Examen I
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.edu.ubilapaz; | |
/** | |
* Created by HP-PC on 29/03/2017. | |
*/ | |
public class Archivo { | |
private String nombre; | |
private String extension; | |
private double peso; | |
public Archivo(String nombre, String extension, double peso) { | |
this.nombre = nombre; | |
this.extension = extension; | |
this.peso = peso; | |
} | |
public Archivo() { | |
this.nombre = ""; | |
this.extension = ""; | |
this.peso = 0; | |
} | |
public String getNombre() { | |
return nombre; | |
} | |
public void setNombre(String nombre) { | |
this.nombre = nombre; | |
} | |
public String getExtension() { | |
return extension; | |
} | |
public void setExtension(String extension) { | |
this.extension = extension; | |
} | |
public double getPeso() { | |
return peso; | |
} | |
public void setPeso(double peso) { | |
this.peso = peso; | |
} | |
} |
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.edu.ubilapaz; | |
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer; | |
import java.util.LinkedList; | |
import java.util.Queue; | |
import java.util.Stack; | |
public class Main { | |
public static void main(String[] args) { | |
Archivo a1 = new Archivo("a", "jpg", 23.4); | |
Archivo a2 = new Archivo("b", "png", 2.4); | |
Archivo a3 = new Archivo("c", "doc", 2.0); | |
Archivo a4 = new Archivo("d", "jpg", 65.2); | |
Archivo a5 = new Archivo("e", "doc", 35.0); | |
Archivo a6 = new Archivo("f", "png", 22.1); | |
Archivo a7 = new Archivo("g", "doc", 12.2); | |
Archivo a8 = new Archivo("h", "doc", 1.1); | |
Archivo a9 = new Archivo("i", "png", 12.1); | |
Archivo a0 = new Archivo("j", "doc", 3.4); | |
Queue<Archivo> colaUSBarchivos = new LinkedList<Archivo>(); | |
colaUSBarchivos.add(a1); | |
colaUSBarchivos.add(a2); | |
colaUSBarchivos.add(a3); | |
colaUSBarchivos.add(a4); | |
colaUSBarchivos.add(a5); | |
colaUSBarchivos.add(a6); | |
colaUSBarchivos.add(a7); | |
colaUSBarchivos.add(a8); | |
colaUSBarchivos.add(a9); | |
colaUSBarchivos.add(a0); | |
System.out.println("---------------Mostrar cola original"); | |
mostrar(colaUSBarchivos); | |
System.out.println("La suma total del USB de archivos es: " + sumaEspacioOcupado(colaUSBarchivos) + " MG"); | |
System.out.println("---------------Separacion de Colas de archivos e Imagenes"); | |
Queue<Archivo> colaUSBfotografias = new LinkedList<Archivo>(); | |
separarFotografias(colaUSBarchivos, colaUSBfotografias); | |
System.out.println("ARCHIVOS:"); | |
mostrar(colaUSBarchivos); | |
System.out.println("FOTOGRAFIAS:"); | |
mostrar(colaUSBfotografias); | |
System.out.println("---------------Mostrar cola inversa"); | |
System.out.println("ARCHIVOS INVERSO"); | |
mostrarColaInversa(colaUSBarchivos); | |
System.out.println("FOTOGRAFIAS INVERSO"); | |
mostrarColaInversa(colaUSBfotografias); | |
} | |
private static void mostrar(Queue<Archivo> a) { | |
int n = a.size(); | |
for (int i = 0; i < n; i++) { | |
Archivo x = a.remove(); | |
System.out.println(x.getNombre() + " | " + x.getExtension() + " | " + x.getPeso()); | |
a.add(x); | |
} | |
} | |
private static void mostrarColaInversa(Queue<Archivo> a) { | |
Stack<Archivo> aux = new Stack<Archivo>(); | |
int n = a.size(); | |
for (int i = 0; i < n; i++) { | |
Archivo x = a.remove(); | |
aux.push(x); | |
} | |
while (!aux.isEmpty()) { | |
Archivo y = aux.pop(); | |
System.out.println(y.getNombre() + " | " + y.getExtension() + " | " + y.getPeso() + " MB"); | |
a.add(y); | |
} | |
} | |
private static double sumaEspacioOcupado(Queue<Archivo> a) { | |
int n = a.size(); | |
double totalEspacio = 0.0; | |
for (int i = 0; i < n; i++) { | |
Archivo x = a.remove(); | |
totalEspacio = totalEspacio + x.getPeso(); | |
a.add(x); | |
} | |
return totalEspacio; | |
} | |
private static void separarFotografias(Queue<Archivo> a, Queue<Archivo> b) { | |
int n = a.size(); | |
for (int i = 0; i < n; i++) { | |
Archivo x = a.remove(); | |
if (x.getExtension() == "jpg" || x.getExtension() == "png") { | |
b.add(x); | |
} else { | |
a.add(x); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment