Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. class Customer {
  2.  
  3. String name;
  4. int ticket;
  5.  
  6. Customer(String name, int ticket) {
  7. this.name = name;
  8. this.ticket = ticket;
  9.  
  10. }
  11.  
  12. String getName() {
  13. return name;
  14.  
  15. }
  16.  
  17. int getTicket() {
  18. return ticket;
  19. }
  20. }
  21.  
  22. public class Main {
  23.  
  24. public static void main(String[] args) {
  25. Queue<Customer> queue = new LinkedList<>();
  26. queue.add(new Customer("a1", 1));
  27. queue.add(new Customer("a2", 2));
  28. queue.add(new Customer("a3", -1));
  29. queue.add(new Customer("a4", -1));
  30.  
  31. queueAnalysis(queue);
  32. }
  33.  
  34. public static void queueAnalysis(Queue<Customer> queue) {
  35.  
  36. System.out.println("Original: " + queue + "n");
  37. String names[] = null;
  38. int cant = 0;
  39. int tam = queue.size();
  40.  
  41. for (int i = 0; i < tam; i++) {
  42. if (queue.peek().getTicket() == -1) {
  43. names[i] = queue.peek().getName();
  44. cant++;
  45. queue.poll();
  46.  
  47.  
  48. }
  49.  
  50. }
  51. System.out.println("colados: " + names + "n");
  52. System.out.println("Cola final: " +queue);
  53.  
  54. //Customer c;
  55. for (Iterator it = queue.iterator(); it.hasNext();) {
  56. System.out.println((Customer) it.next());
  57. }
  58.  
  59. }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement