[Solved] User notification with Java

User notification: It is an important aspect for every application to be as user-friendly as possible. So that means it needs to send mails, messages whenever needed to the users. Write a thread program that sends the users notification after getting each of their names and number.

Strictly adhere to the Object-Oriented specifications given in the problem statement. All class names, attribute names, and method names should be the same as specified in the problem statement.


Create a Class User with the following attributes

AttributesDatatype
userNameString
mobileNumberString


Generate getters and setters, create default and parameterized constructors in the following order: User(String userName, String mobileNumber)

 

Create a class UserBO which extends Thread class with the following public attributes,

AttributesDatatype
userListList<User>
static messageList<String>

Override the following methods in the UserBO class,

Method nameDescription
public void run()In this method, create a synchronized block and get the user name, and mobile number from the userList and create a notification message and add it to the message list. 
The notification message should be like below,
The message is sent to the user “userName” at the mobile number “mobileNumber”

Get the number of users, number of users per thread, and user details and generate a list of notification for the users. 
Create multi-threads according to the inputs and add users to the corresponding list in the thread.
Create a driver class Main to test the above requirements.

Input Format
The first line of the input corresponds to the total number of users ‘n’.
The second line of the input corresponds to the number of users per thread.
The next ‘n’ line of input contains user details (user name, mobile number) separated by comma[,].

Output Format
The output consists of the notification for all the users.
Refer to sample output for formatting specifications.

[All text in bold corresponds to input and rest corresponds to output]
Sample Input/Output:

Enter the number of users:
6
Enter the number of users per thread:
2
Enter the user details
Sarah,9876543210
Richard,4567894564
Arya,4569871233
Stephanie,879879789
Sheldon,7878787987

Oliver,8989898987
The message is sent to the user Sarah at the mobile number 9876543210
The message is sent to the user Richard at the mobile number 4567894564
The message is sent to the user Arya at the mobile number 4569871233
The message is sent to the user Stephanie at the mobile number 879879789
The message is sent to the user Sheldon at the mobile number 7878787987
The message is sent to the user Oliver at the mobile number 8989898987

Solution

import java.util.*;
public class Main {
    public static void main(String[] args)  {
		Scanner sc=new Scanner(System.in);
        System.out.println("Enter the number of users:");
        String num=sc.nextLine();
        int a=Integer.parseInt(num);
        System.out.println("Enter the number of users per thread:");
        String num1=sc.nextLine();
        int a1=Integer.parseInt(num1);
        System.out.println("Enter the user details");
        ArrayList<String> name=new ArrayList<>();
        ArrayList<String> mob=new ArrayList<>();
        for(int i=0;i<a;i++){
            String t=sc.nextLine();
            String[] arr=t.split(",");
            name.add(arr[0]);
            mob.add(arr[1]);
        }
       
       for(int j=0;j<name.size();j++){
           System.out.println("The message is sent to the user "+name.get(j)+" at the mobile number "+mob.get(j));
           
       }
	}
}

Happy Learning – If you require any further information, feel free to contact me.

Share your love
Saurav Hathi

Saurav Hathi

I'm currently studying Bachelor of Computer Science at Lovely Professional University in Punjab.

📌 Nodejs and Android 😎
📌 Java

Articles: 444

Leave a Reply

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