How To Make Cell Phone Network Provider And PhoneNumber Generator Using Java And Netbeans 8.2 (GUI Application)

How To Make Cell Phone Network Provider And PhoneNumber Generator Using Java And Netbeans 8.2 (GUI Application)

SOURCE CODE

CellPhoneNetworkProviderAndPhoneNumberGenerationDriver.java

/*
 * How To Make Cell Phone Network Provider And PhoneNumber Generator Using Java And Netbeans 8.2 (GUI Application)
 * https://mauricemuteti.info/how-to-make-cell-phone-network-provider-and-phonenumber-generator-using-java-and-netbeans-8-2-gui-application/
 */
package cellphonenetworkproviderandphonenumbergenerationjava;

import java.util.ArrayList;
import java.util.Random;
import javax.swing.JOptionPane;

/**
 *
 * @author HP
 */
public class CellPhoneNetworkProviderAndPhoneNumberGenerationDriver {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

        //Storing cell Phone Network Provider In String Array.
        String[] cellPhoneNetworkProviders = new String[]{"CELL C", "VODACOM", "MTN"};
//        cellPhoneNetworkProviders[0] = "CELL C";
//        cellPhoneNetworkProviders[1] = "VODACOM";
//        cellPhoneNetworkProviders[2] = "MTN";

        //String Arrays.
        String[] employees = new String[3];
        String[] phoneNumner = new String[3];
        String[] networkProvider = new String[3];

        //Creating Employee Object.
        Employee employee = null;
        //Creating Employee ArrayList.
        ArrayList<Employee> emps = new ArrayList<>();
        //Creating x integer variable. 
        int x = 0;

        //While Loop.
        while (x < 3) {
            String randomlyGeneratedCellPhoneNetworkProvider = getRandomNetworkProvider(cellPhoneNetworkProviders);
            employees[x] = JOptionPane.showInputDialog("Enter Name : ");
            networkProvider[x] = randomlyGeneratedCellPhoneNetworkProvider;
            phoneNumner[x] = getPhone(randomlyGeneratedCellPhoneNetworkProvider);
            //Initializing employee object and passing data using parameterized constructor.
            employee = new Employee(employees[x], networkProvider[x], phoneNumner[x]);

            //Adding employees to the arraylist.
            emps.add(employee);
            //Incrementing variable x counter variable.
            x++;
        }

        //Creating Empty Output String variable.
        String output = "";

        //Displaying all employees data using for loop.
        for (Employee emp : emps) {
            //Appending output with employee data.
            output += emp.getName() + " Will Be On the " + emp.getCellPhoneNetworkProvider() + " Network With Phonenumber " + emp.getCellPhoneNumber() + "\n";
        }

        //JOptionPane Dialog box output.
        JOptionPane.showMessageDialog(null, output);

    }

    /**
     * Method for Generating phone number based on CellPhoneNetworkProvider.
     *
     * @param randomlyGeneratedCellPhoneNetworkProvider
     * @return
     */
    public static String getPhone(String randomlyGeneratedCellPhoneNetworkProvider) {
        String phoneNumber = "";
        switch (randomlyGeneratedCellPhoneNetworkProvider) {
            //Case CELL C
            case "CELL C":
                phoneNumber = "084 " + getRandomThreePhoneNumbers() + " - (" + getRandomFourPhoneNumbers() + ")";
                break;
            //Case VODACOM
            case "VODACOM":
                phoneNumber = "072 " + getRandomThreePhoneNumbers() + " - (" + getRandomFourPhoneNumbers() + ")";
                break;
            //Case MTN
            case "MTN":
                phoneNumber = "083 " + getRandomThreePhoneNumbers() + " - (" + getRandomFourPhoneNumbers() + ")";
                break;
        }
        return phoneNumber;
    }

    /**
     * Method For Randomly picking an element(NetworkProvider) from an array.
     *
     * @param array
     * @return
     */
    public static String getRandomNetworkProvider(String[] array) {
        int random = new Random().nextInt(array.length);
        return array[random];
    }

    /**
     * Method For Generating random three numbers.
     *
     * @return
     */
    public static int getRandomThreePhoneNumbers() {
        // Creating and initializing a Random object.
        Random random = new Random();
        // generate a random integer from 0 to 899, then add 100
        int x = random.nextInt(900) + 100;
        return x;
    }

    /**
     * Method For Generating random four numbers.
     *
     * @return
     */
    public static int getRandomFourPhoneNumbers() {
        //Creating and initializing a Random object.
        Random random = new Random();
        // generate a random integer from 0 to 8999, then add 1000.
        int x = random.nextInt(9000) + 1000;
        return x;
    }
}

Employee.java

/*
 * How To Make Cell Phone Network Provider And PhoneNumber Generator Using Java And Netbeans 8.2 (GUI Application)
 * https://mauricemuteti.info/how-to-make-cell-phone-network-provider-and-phonenumber-generator-using-java-and-netbeans-8-2-gui-application/
 */
package cellphonenetworkproviderandphonenumbergenerationjava;

/**
 *
 * @author HP
 */
public class Employee {

    //Instance variable.
    private String name;
    private String cellPhoneNetworkProvider;
    private String cellPhoneNumber;

    /**
     *
     */
    public Employee() {
    }

    /**
     * Constructor With Parameters.
     *
     * @param name
     * @param cellPhoneNetworkProvider
     * @param cellPhoneNumber
     */
    public Employee(String name, String cellPhoneNetworkProvider, String cellPhoneNumber) {
        this.name = name;
        this.cellPhoneNetworkProvider = cellPhoneNetworkProvider;
        this.cellPhoneNumber = cellPhoneNumber;
    }

    /**
     * Get the value of cellPhoneNumber
     *
     * @return the value of cellPhoneNumber
     */
    public String getCellPhoneNumber() {
        return cellPhoneNumber;
    }

    /**
     * Set the value of cellPhoneNumber
     *
     * @param cellPhoneNumber new value of cellPhoneNumber
     */
    public void setCellPhoneNumber(String cellPhoneNumber) {
        this.cellPhoneNumber = cellPhoneNumber;
    }

    /**
     * Get the value of cellPhoneNetworkProvider
     *
     * @return the value of cellPhoneNetworkProvider
     */
    public String getCellPhoneNetworkProvider() {
        return cellPhoneNetworkProvider;
    }

    /**
     * Set the value of cellPhoneNetworkProvider
     *
     * @param cellPhoneNetworkProvider new value of cellPhoneNetworkProvider
     */
    public void setCellPhoneNetworkProvider(String cellPhoneNetworkProvider) {
        this.cellPhoneNetworkProvider = cellPhoneNetworkProvider;
    }

    /**
     * Get the value of name
     *
     * @return the value of name
     */
    public String getName() {
        return name;
    }

    /**
     * Set the value of name
     *
     * @param name new value of name
     */
    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Employee{" + "name=" + name + ", cellPhoneNetworkProvider=" + cellPhoneNetworkProvider + ", cellPhoneNumber=" + cellPhoneNumber + '}';
    }

}


Netbeans 8.2 OUTPUT SCREENSHOTS

DEMO VIDEO

Leave a Reply

Your email address will not be published. Required fields are marked *