1 Reply Latest reply on May 18, 2013 11:45 PM by EJP

    java program


      Structure of the file is as follows:

      The first 8 characters indicate the employee number
      Next 3 characters are delimiter ***
      Next 8 characters are date shown in ddmmyyyy format
      Next 3 characters are delimiter ***
      Next 6 characters are time in hhmmsss (24 hour format)
      Next 3 characters are delimiter ***
      Last 5 characters show whether it is an entry into the work area or
      exit from the premises. 10001 indicates entry and 10101 indicates

      Three employees join the organization on June 2, 2008. They are given
      ID cards and the respective employee numbers are encoded on to the
      cards. It is expected that they flash their cards every time they
      enter the premises or enter their work area. Card readers have been
      installed at all entry & exit points in the building. First record
      for indicator 10001 shows the attendance-in and last record for
      indicator 10101 shows swipe-out. Sample input text data shown above
      contains the swipe entries of these three employees.

      It is expected that the text file is not sorted at all (as you can see
      in the sample input file) and you need to sort them. Unfortunately,
      the specification does not say anything about the order in which the
      file has to be sorted. The onus is on you to determine the sort

      Given the text file, you are expected to do the following:

      1. Print an output which shows the employee code, date, total time
      worked by the employee (swipe-out minus attendance-in) and remarks.
      2. If there is no attendance-in but there is a swipe-out for a given
      date, total time is 0, remarks to mention "No attendance-in"
      3. If there is an attendance-in for a given date but no swipe-out,
      total time is 0, remarks to mention "No swipe-out"

      You can very well ignore the added complexity of absences, weekends
      and public holidays. If there is a record in the file, you need to
      compute and display output.

      If a record contains any other structure, you can ignore that record
      and print an error log separately at the end of the output.

      Given this requirement, write a Java program to display the desired output.

      A few hints -

      a. Using Java collections framework will help you solve this problem
      in a better way
      b. All input value is of type String. While sorting date, please be
      careful as you would end up doing a lexicographical sorting. You need
      to think a better way of representing date values.
      c. Your sort algorithm has to be efficient; avoid unnecessary loop
      passes or iterations
      d. Avoid Singleton and threads for this problem. It will
      over-complicate your design and coding. You can use them later.

      A few more clarifications:

      1. You are expected to get input from the user. Possibly, you can
      use a file handler to get the input file from user. You must not
      hardcode for input values. Neither can you expect the user to enter
      the string repeatedly for every record in the file nor can you code
      with such a premise in mind. Your code must run for a few hundreds or
      thousand of records that are part of the input text file. The reason
      is simple - when you get data from a text file, you need to use

      2. Something about type-safety. Especially when you use collections,
      Java expects you to check for type-safety as part of your code using
      Generics. You don't need to get into details about Generics. For
      this problem, please include the data / class type when you write

      For example, if you are collection is a Set of strings, please mention -

      Set<String> str = new HashSet<String>();

      3. Pay attention to sorting. Check for the appropriate data type.
      You may fall into a potential trap if the scope of the program is
      expanded to include a few other things that span across multiple
      dates. For eg., is the string value 31052008 lower than 02062008 ?
      Think about it.

      4. If you don't know any libraries, then write a method to find time
      difference which you can reuse it during every iteration.

      Some more clarifications:

      Once sorted, the sample input data is as given below:


      For employee 00990001:

      First record for 10001 for 02062008 - 08:28:50
      Last record for 10101 for 02062008 - 19:07:50

      Time worked = 19:07:50 - 08:28:50 = 10:39:00 (Please calculate - I did
      some mental calculation and I may be wrong)

      For employee 00990003:

      First record for 10001 for 02062008 - 08:58:50
      Last record for 10001 for 02062008 - 19:00:07

      Time worked = 19:00:07 - 08:58:50 = 10:01:17 (please check this one too)

      For employee 00990002:

      There is no swipe-out indicator and hence appropriate remarks to be
      mentioned. Time worked to be marked as 0 as given in the requirement.