The organisation you work for has asked you to create an interactive application that will assist with the allocation of employees to a cell phone network provider and phone number generation. You are required to prompt a user for three employee names which will randomly assign the employee to either the Vodacom, MTN or Cell C network. The employees also require a randomly generated phone number. The start of each phone number will begin with the following, depending on the network provider: NETWORK PROVIDER START Vodacom 072 MTN 083 Cell C 084 The remaining numbers of the phone number must be randomly generated
import java.util.Random;
import java.util.Scanner;
public class Q200840 {
private static Random random;
private static String providers[] = { "Vodacom", "MTN", "Cell C" };
public static void main(String[] args) {
random = new Random();
Scanner scanner = new Scanner(System.in);
String employeeNames[] = new String[3];
String employeeNetworkProviders[] = new String[3];
String employeePhones[] = new String[3];
for (int i = 0; i < 3; i++) {
System.out.print("Enter the employee name " + (i + 1) + ": ");
employeeNames[i] = scanner.nextLine();
employeeNetworkProviders[i] = getRandomProvider(employeeNetworkProviders);
employeePhones[i]="072 ";
if(employeeNetworkProviders[i]==providers[1]) {
employeePhones[i]="083 ";
}
if(employeeNetworkProviders[i]==providers[2]) {
employeePhones[i]="084 ";
}
for(int p=0;p<3;p++) {
employeePhones[i] += random.nextInt(10);
}
employeePhones[i] += "-(";
for(int p=0;p<4;p++) {
employeePhones[i] += random.nextInt(10);
}
employeePhones[i] += ")";
}
for (int i = 0; i < 3; i++) {
System.out.println("The employee name: " + employeeNames[i]);
System.out.println("The employee network provider: " + employeeNetworkProviders[i]);
System.out.println("The employee phone number: " + employeePhones[i] + "\n");
}
scanner.close();
}
/**
* Returns random provider
* @param employeeNetworkProviders
* @return
*/
private static String getRandomProvider(String employeeNetworkProviders[]) {
int randomIndex = -1;
while (randomIndex==-1) {
randomIndex = random.nextInt(3);
for (int provider = 0; provider < 3; provider++) {
if (employeeNetworkProviders[provider] == providers[randomIndex]) {
randomIndex = -1;
break;
}
}
}
return providers[randomIndex];
}
}
Comments
Dear Shafeeq
This program is not running
Leave a comment