-
-
Save GlebGomenyuk/bbf8899175ca8e39a790fba81093a724 to your computer and use it in GitHub Desktop.
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 com; | |
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
Phone phone = new Phone(); | |
Scanner scan = new Scanner(System.in); | |
System.out.println("Введите желаемый номер телефона "); | |
String numberPhone = scan.nextLine(); | |
phone.setInputPhone(numberPhone); | |
phone.net(numberPhone); | |
} | |
} |
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 com; | |
import javax.swing.plaf.basic.BasicInternalFrameTitlePane.CloseAction; | |
public class Network { | |
private String[] operator = {"093","063", "066","050"}; | |
int col = 0; | |
public void serc(String networks) { | |
for (int i = 0; i < operator.length; i++) { | |
if(networks.equals(operator[i])) { | |
System.out.println("Оператор существует "); | |
} | |
else { | |
col ++; | |
} | |
} | |
if(col>operator.length-1) { | |
System.out.println("Данного оператора не существует "); | |
System.exit(0); | |
} | |
System.out.println(); | |
} | |
} |
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 com; | |
import java.util.Scanner; | |
public class Phone { | |
Network net = new Network(); | |
private String inputPhone; | |
public String getInputPhone() { | |
return inputPhone; | |
} | |
public void setInputPhone(String inputPhone) { | |
this.inputPhone = inputPhone; | |
} | |
private String[] numberPhone = { "0930560342", "0667534563", "093097854321" }; | |
public Phone() { | |
super(); | |
} | |
public Phone(String[] numberPhone) { | |
super(); | |
this.numberPhone = numberPhone; | |
} | |
public void net(String inputPhone) { | |
char[] network = inputPhone.toCharArray(); | |
String networks = ("" + network[0] + network[1] + network[2]); | |
net.serc(networks); | |
registration(inputPhone); | |
} | |
public void registration(String inputPhone) { | |
int col = 0; | |
for (int i = 0; i < numberPhone.length; i++) { | |
if (inputPhone.equals(numberPhone[i])) { | |
System.out.println("Данный номер занят "); | |
break; | |
} | |
} | |
if (col == 0 && inputPhone.length() == 10) { | |
System.out.println("Ваш номер " + inputPhone); | |
System.out.println("Куда вы хотите позвонить? "); | |
Scanner scan = new Scanner(System.in); | |
String callPhone = scan.nextLine(); | |
call(callPhone); | |
} else { | |
System.out.println("Ошибка. Возможно вы ввели лишнюю цифру. "); | |
System.exit(0); | |
} | |
} | |
public void call(String callPhone) { | |
int col = 0; | |
String inputPhone = this.inputPhone; | |
for (int i = 0; i < numberPhone.length; i++) { | |
if(callPhone.equals(numberPhone[i]) || callPhone.equals(inputPhone)) { | |
System.out.println("Вы звоните на не существующий номер телефона либо на свой! Ошибка! " + inputPhone); | |
break; | |
} | |
} | |
if(col==0) { | |
System.out.println(" Идет вызов на номер " + callPhone); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment