3
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 Task4; 7 8 import java.util.Scanner; 9 10 /** 11 * 12 * @author Tyler 13 */ 14 public class MainTask4 { 15 public static void main(String[] args) { 16 Queue phoneCallQueue = new Queue(); 17 while(true){ 18 System.out.println("Please choose an option: "); 19 System.out.println("1) Add phone call"); 20 System.out.println("2) Answer phone call"); 21 System.out.println("3) List Phone Calls"); 22 Scanner input = new Scanner(System.in); 23 String choice = input.nextLine(); 24 if (choice.equals("1")){ 25 System.out.println("Please add name: "); 26 String name = input.nextLine(); 27 System.out.println("Please add phone number: "); 28 String number = input.nextLine(); 29 PhoneCall pc = new PhoneCall(name, number); 30 phoneCallQueue.push(pc); 31 } 32 if (choice.equals("2")){ 33 phoneCallQueue.pop(); 34 } 35 if (choice.equals("3")){ 36 phoneCallQueue.printAllQueue(); 37 } 38 } 39 } 40 }

Company Call System

Embed Size (px)

Citation preview

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 Task4;

7

8 import java.util.Scanner;

9

10 /**

11 *

12 * @author Tyler

13 */

14 public class MainTask4 {

15 public static void main(String[] args) {

16 Queue phoneCallQueue = new Queue();

17 while(true){

18 System.out.println("Please choose an option: ");

19 System.out.println("1) Add phone call");

20 System.out.println("2) Answer phone call");

21 System.out.println("3) List Phone Calls");

22 Scanner input = new Scanner(System.in);

23 String choice = input.nextLine();

24 if (choice.equals("1")){

25 System.out.println("Please add name: ");

26 String name = input.nextLine();

27 System.out.println("Please add phone number: ");

28 String number = input.nextLine();

29 PhoneCall pc = new PhoneCall(name, number);

30 phoneCallQueue.push(pc);

31 }

32 if (choice.equals("2")){

33 phoneCallQueue.pop();

34 }

35 if (choice.equals("3")){

36 phoneCallQueue.printAllQueue();

37 }

38 }

39 }

40 }

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 Task4;

7

8 /**

9 *

10 * @author Tyler

11 */

12 public class PhoneCall {

13 private String name;

14 private String phoneNumber;

15

16 public PhoneCall(String name, String phoneNumber) {

17 this.name = name;

18 this.phoneNumber = phoneNumber;

19 }

20

21 public String getName() {

22 return name;

23 }

24

25 public void setName(String name) {

26 this.name = name;

27 }

28

29 public String getPhoneNumber() {

30 return phoneNumber;

31 }

32

33 public void setPhoneNumber(String phoneNumber) {

34 this.phoneNumber = phoneNumber;

35 }

36

37

38 }

39

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 Task4;

7

8 /**

9 *

10 * @author Tyler

11 */

12 public class Queue {

13 PhoneCall[] queue = null;

14 int freeSpace ;

15 public Queue() {

16 queue = new PhoneCall[10];

17 freeSpace = 0;

18 }

19

20 public void pop(){

21 for (int i = 0; i < 9; i++) {

22 queue[i] = queue[i+1];

23 }

24 freeSpace--;

25 }

26 public void push(PhoneCall phoneCall){

27 queue[freeSpace++] = phoneCall;

28 }

29

30 public void printAllQueue(){

31 for (int i = 0; i < 10; i++) {

32 if(queue[i]==null)

33 System.out.println(queue[i]);

34 else

35 System.out.println( i+". Phone number :"+queue[i].getPhoneNumber()+" Name

:"+queue[i].getName());

36 }

37 }

38 }