Advertisement
Dakufuren

Untitled

Oct 26th, 2014
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.88 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package sem3task4;
  7.  
  8. import java.util.ArrayList;
  9. import java.util.Scanner;
  10.  
  11. /**
  12.  *
  13.  * @author Albin
  14.  */
  15. public class Sem3Task4 {
  16.    
  17.    
  18.     public int i = 0;
  19.     public PhoneQueue [] queue = new PhoneQueue[10];
  20.     Scanner scan = new Scanner(System.in);
  21.    
  22.     /**
  23.      * @param args the command line arguments
  24.      */
  25.     public static void main(String[] args) {
  26.         Sem3Task4 call = new Sem3Task4();
  27.         Scanner scan = new Scanner(System.in);
  28.        
  29.         int menunr;
  30.        
  31.         while (true) {
  32.         System.out.println("Menu");
  33.         System.out.println("________________________");
  34.         System.out.println("1. Add Queue");
  35.         System.out.println("2. Answer Queue");
  36.         System.out.println("3. Exit System");
  37.         System.out.println("________________________");
  38.        
  39.         menunr = scan.nextInt();
  40.         if (menunr == 1){
  41.             call.addQueue();
  42.                
  43.         }
  44.        
  45.         else if (menunr == 2){
  46.             call.rmQueue();
  47.            
  48.         }
  49.        
  50.         else if (menunr == 3){
  51.             System.exit(0);
  52.                
  53.         }
  54.        
  55.         else {
  56.             System.out.println("Need to be a number between 1-3");
  57.         }
  58.     }
  59. }
  60.    
  61.     public void addQueue(){
  62.            
  63.            
  64.             if (i == 10) {
  65.                 System.out.println("Too many calls in queue");
  66.             }
  67.  
  68.             else  {
  69.             System.out.println("Print the name of the caller");
  70.             String callname = scan.nextLine();
  71.  
  72.             System.out.println("Print the number of the caller");
  73.             String callphonenr = scan.nextLine();
  74.            
  75.             System.out.println();
  76.                
  77.             queue[i] = new PhoneQueue();
  78.             queue[i].setName(callname);
  79.             queue[i].setPhonenr(callphonenr);
  80.            
  81.             System.out.println();
  82.             System.out.println("Call Added to Queue");
  83.             System.out.println(queue[i].getName() + " " +  queue[i].getPhonenr());
  84.             i++;
  85.             }
  86.  
  87.     }
  88.    
  89.    
  90.     public void rmQueue(){
  91.        
  92.             if (i > 0) {
  93.                 i--;
  94.             }
  95.  
  96.             System.out.println();
  97.             System.out.println();
  98.             int j = 9;
  99.            
  100.             for(int z = 0; z <= 8; z++) {
  101.                
  102.                 System.out.println();
  103.                 System.out.println("Moving " + queue[z].getName()+ "-> " + queue[z+1].getName());
  104.                
  105.             queue[z] = queue[z+1];
  106.            
  107.                 System.out.println(queue[z].getName());
  108.                 System.out.println();
  109.             }
  110.          
  111.         }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement