Alexis-Coria

Tp03-Punto05

Nov 8th, 2021
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.83 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Punto05 {
  4. public static void main(String[] args) {
  5. Queue<Correo> bandejaEntrada = new Queue<>();
  6. Queue<Correo> bandejaPrincipal = new Queue<>();
  7. Queue<Correo> bandejaSocial = new Queue<>();
  8. Queue<Correo> bandejaPromociones = new Queue<>();
  9. Scanner entrada = new Scanner(System.in);
  10. int cont =0;
  11. while (cont!=4){
  12. switch(cont){
  13. case 1:
  14. recibirCorreo(entrada,bandejaEntrada);
  15. separarCorreos(bandejaEntrada,bandejaPrincipal,bandejaSocial,bandejaPromociones);
  16. break;
  17. case 2:
  18. correoRandom(bandejaEntrada,entrada);
  19. separarCorreos(bandejaEntrada,bandejaPrincipal,bandejaSocial,bandejaPromociones);
  20. break;
  21. case 3:
  22. mostrarBandejas(bandejaPrincipal,bandejaSocial,bandejaPromociones);
  23. break;
  24. }
  25. cont=Helper.elegirOpcion(entrada, "'Bandeja de correos' \n1-Manual \n2-Random \n3-Ver bandejas de correo \n4-Salir");
  26. }
  27.  
  28. }
  29.  
  30.  
  31.  
  32. public static void recibirCorreo(Scanner entrada, Queue<Correo> bandeja) {
  33. Correo correo;
  34. String remitente,asunto,cuerpo;
  35. int continuar;
  36. do{
  37. remitente = Helper.cargarLetra(entrada, "Ingrese remitente: ");
  38. asunto = Helper.cargarLetra(entrada, "Ingrese asunto: ");
  39. cuerpo = Helper.cargarLetra(entrada, "Ingrese cuerpo: ");
  40. correo = new Correo(remitente, asunto, cuerpo);
  41. bandeja.offer(correo);
  42. continuar = Helper.elegirOpcion(entrada,"'opcion' \n1-Seguir Cargando \n2-Salir");
  43. } while(continuar!=2);
  44. }
  45.  
  46.  
  47.  
  48. private static void correoRandom(Queue<Correo> bandejaEntrada,Scanner entrada) {
  49. Correo correo;
  50. String remitente,asunto,cuerpo;
  51. int continuar;
  52. do{
  53. remitente = nombreRandom("Generando remitente aleatorio...");
  54. asunto = asuntoRandom("Generando asunto aleatorio...");
  55. System.out.println("Generando un cuerpo de correo...");
  56. cuerpo = ("Recibiste una notificacion de "+asunto +" enviada por "+remitente);
  57. correo = new Correo(remitente, asunto, cuerpo);
  58. bandejaEntrada.offer(correo);
  59. continuar = Helper.elegirOpcion(entrada,"'opcion' \n1-Seguir Cargando \n2-Salir");
  60. } while(continuar!=2);
  61.  
  62. }
  63.  
  64. public static String nombreRandom(String mensaje){
  65. int random;
  66. System.out.println(mensaje);
  67. String [] nombre ={"Domingo Galan","Ricardo Ribas ","Erik Diego","Abel Valdivia","Laila PiƱeiro","Delfina Torralba","Florencia Alvaro","Ariadna Espin","Angelina Manso","Martina Ros"};
  68. random = (int) (Math.random() * nombre.length);
  69. return nombre[random];
  70. }
  71.  
  72. public static String asuntoRandom(String mensaje){
  73. int random;
  74. System.out.println(mensaje);
  75. String [] nombre ={"Facebook","Twitter","Youtube","Instagram","Promocion","Oferta","Viajes","Venta","Urgencia","Saludo familiar","Reunion"};
  76. random = (int) (Math.random() * nombre.length);
  77. return nombre[random];
  78. }
  79.  
  80. public static void separarCorreos(Queue<Correo> bandeja, Queue<Correo> bandejaPrincipal, Queue<Correo> bandejaSocial, Queue<Correo> bandejaPromociones) {
  81. Correo identificar;
  82. String remitente,asunto,cuerpo;
  83. int continuar;
  84. while(!bandeja.estaVacia()){
  85. identificar =(Correo) bandeja.pool();
  86. if (identificar.getAsunto().equalsIgnoreCase("Facebook") || identificar.getAsunto().equalsIgnoreCase("Youtube") || identificar.getAsunto().equalsIgnoreCase("Instagram")|| identificar.getAsunto().equalsIgnoreCase("Twitter")){
  87. bandejaSocial.offer(identificar);
  88. continue;
  89. }
  90. if (identificar.getAsunto().equalsIgnoreCase("Oferta") || identificar.getAsunto().equalsIgnoreCase("Venta") || identificar.getAsunto().equalsIgnoreCase("Viajes")|| identificar.getAsunto().equalsIgnoreCase("Promocion")){
  91. bandejaPromociones.offer(identificar);
  92. continue;
  93. }
  94. else {
  95. bandejaPrincipal.offer(identificar);
  96. }
  97.  
  98. }
  99. }
  100.  
  101.  
  102. public static void mostrarBandejas(Queue<Correo> bandejaPrincipal, Queue<Correo> bandejaSocial, Queue<Correo> bandejaPromociones) {
  103. System.out.println("Bandeja de entrada vacia...");
  104. System.out.println("Bandeja Principal: "+bandejaPrincipal.toString());
  105. System.out.println("Bandeja Social: "+bandejaSocial.toString());
  106. System.out.println("Bandeja de Promociones: "+bandejaPromociones.toString());
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment