Answer to Question #200840 in Java | JSP | JSF for Thabby

Question #200840

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


1
Expert's answer
2021-05-30T14:54:46-0400
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];
	}


}





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Assignment Expert
07.06.21, 14:10

Dear Shafeeq

save the code into Q200840.java
run javac Q200840.java
run java  Q200840

Shafeeq
07.06.21, 14:08

This program is not running

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS