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 Q197713 {
public static void main(String[] args) {
// Scanner object
Scanner in = new Scanner(System.in);
Random rand = new Random();
String providers[] = { "Vodacom", "MTN", "Cell C" };
String names[] = new String[3];
String networkProviders[] = new String[3];
String phones[] = new String[3];
for (int i = 0; i < 3; i++) {
System.out.print("Enter the employee name " + (i + 1) + ": ");
names[i] = in.nextLine();
boolean isProviderValid = false;
int randP = 0;
while (!isProviderValid) {
isProviderValid = true;
randP = rand.nextInt(3);
for (int provider = 0; provider < 3; provider++) {
if (networkProviders[provider] == providers[randP]) {
isProviderValid = false;
}
}
}
networkProviders[i] = providers[randP];
phones[i] = networkProviders[i] + " 0" + rand.nextInt(10) + rand.nextInt(10);
System.out.println("The employee network provider is: " + networkProviders[i]);
System.out.println("The employee phone number is: " + phones[i] + "\n");
}
// close Scanner
in.close();
}
}
Comments
Leave a comment