AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



corejava-programming: Program to provide the count of absentees and swipe defaulters

One Monday Sourabh decided to check the swipe record and found out the number of absentees and the swipe defaulters (people who do not complete 9 working hours). For the same he asked you to write a java program which will take the number of trainees and their swipe in and swipe-out time (don´t consider lunch break) and as a response i will provide the count of absentees and swipe defaulters as output.
Input Specification:
--------------------------------
First input n will take the number of trainee(trainees will be identified by number from 1 to n) where 1<=n<=500 Until user input 0(representing end of the day) input trainee id and in/out time(hh:mm). once trainee is IN, next input of same id represents OUT time and it is mandatory to have OUT time for all IN times)
Output Specification:
---------------------------------
Will contain 2 integer values: the first one representing number of absentees and second integer representing the number of swipe defaulters.
Sample input:
-----------------------------
5
2 8:30
3 9:05
2 17:30
3 17:30
0
Sample output:
-------------------------------
3
1

corejava x 348
programming x 165
Posted On : 2018-01-18 17:07:09.0
profile Divesh - anyforum.in Divesh
102160
up-rate
2
down-rate

Answers


import java.util.Scanner;

public class DefaulterCounter{
public static void main(String[] args) throws Exception{
Scanner input=new Scanner(System.in);
int n=Integer.valueOf(input.nextLine().trim());
if(1<=n && n<=500){
String[] inTime=new String[n];
String[] outTime=new String[n];
String[] entity;
String[] entity1;
int index;
int defaulters=0;
int absentees=0;
int count=0;
int hh=0;
int mm=0;
String line;
while(!(line=input.nextLine().trim()).equalsIgnoreCase("0")){
entity = line.split(" ");
index=Integer.valueOf(entity[0])-1;
if(inTime[index]==null){
inTime[index]= entity[1];
count++;
}
else{
outTime[index]= entity[1];
entity=outTime[index].split(":");
entity1=inTime[index].split(":");
hh=Integer.valueOf(entity[0])-Integer.valueOf(entity1[0]);
mm=Integer.valueOf(entity[1])-Integer.valueOf(entity1[1]);
if(hh<9 || (hh==9 && mm<0))
defaulters++;
}
}
absentees=n-count;
System.out.println(absentees);
System.out.println(defaulters);
}else{
throw new Exception("Invalid Auguments!");
}
}
}

Posted On : 2018-01-26 18:06:57
Satisfied : 1 Yes  0 No
profile Rishi Kumar - anyforum.in Rishi Kumar
523186220593
Reply This Thread
up-rate
0
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in