Answer to Question #197713 in Java | JSP | JSF for Chrissy

Question #197713

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-24T04:11:30-0400
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();
	}


}




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

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS