[Solved] Event entry with Java

Event entry: The Fair participants will be given RFID tags that allow them to enter or exit a stall, events seamlessly. The Entry/Exit entries will be connected to the mainframe server. Any organizer should be able to monitor the crowd density of his/her event/stall. Hence by accessing the entries, compute the number of current participants in the event/stall. Use threads to aid the computing process.

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 Event which extends Thread class with the following private attributes,

AttributesDatatype
entryString

Create a default constructor and a parameterized constructor with arguments in order Event(String entry). Create appropriate getters and setters.

Override the following methods in the Event class,

Method Description
public void run()In this method, call the processEvent method and pass the entry String as a parameter.

Create a class EventBO with the following static variables,

AttributesDatatype
currentPeopleCountstatic Integer

Create the following static methods in EventBO class,

Method Description
public static void processEvent(String enterType)In this method,
get the enter type as String and split them into individual readings.
If the reading is “Entry” increment the currentPeopleCount by one,
if the reading is “Exit” decrement the currentPeopleCount by one.
This process should be done inside the synchronized block.

Get the input and form the list of events with the given enter types. Initially assign the currentPeopleCount as 0 and Calculate the current People Count in the event by spanning each event into separate threads and calculate the current People Count.

Create a driver class Main to test the above requirements.

Input Format:
The First line of input consists of the number of sensors(n).
The next ‘n’ line contains sensor reading separated by spaces.

Output Format:
The output consists of the current People Count in the event.
Refer to sample output for formatting specifications.

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


Enter the number of Entry/Exit sensors:
3
Enter the sensor readings
Entry Entry Entry Exit
Exit Exit Entry Entry Entry
Entry Entry Entry Entry Exit

The number of current participants are 6

Solution

import java.util.*;
public class Main {
    public static void main(String[] args)  {
    	System.out.println("Enter the number of Entry/Exit sensors:");
        Scanner sc=new Scanner(System.in);
        String num=sc.nextLine();
        Integer n=Integer.parseInt(num);
        int ent=0,exit=0;
        System.out.println("Enter the sensor readings");
        for(int i=0;i<n;i++){
            String temp=sc.nextLine();
            String[] arr=temp.split(" ");
            for(int j=0;j<arr.length;j++){
                if(arr[j].equals("Entry")){
                    ent+=1;
                }else{exit+=1;}
            }
        }
        System.out.println("The number of current participants are "+(ent-exit));
        
	}
}

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

2 Comments

Leave a Reply

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