0

Please check my code.

I am trying to store information from excel to a object and based on search criteria, I am trying to get the values in console.

public class Assignment3 {

    public static void main(String[] args) {

        String filePath = "E:\\Java_All\\Assignment\\PreAuthOrig2.csv";

        excelRead data = getMemberDetails(filePath, "1001") ;
        System.out.println(data.toString());

    }

    public static excelRead getMemberDetails (String filePath, String MemberID)
    {

        try
        {

            BufferedReader br = new BufferedReader (new FileReader (filePath));
            String readexcel;

            List<excelRead> dataList = new ArrayList <excelRead>();

            while ((readexcel = br.readLine()) !=null)
            {
                excelRead readLines = new excelRead();
                String lines[] = readexcel.split(",");

                readLines.setMemberID(lines[0]);

                //* requirement 2 : if member id is 1002, then update Reviewer name as John and Reviewer status = Pending *\\

                if (lines[0] == "1002")
                {
                    readLines.setReviewerName("John");
                    readLines.setReviewStatus("Pending");

                }

                else
                {
                    readLines.setReviewerName(lines[6]);
                    readLines.setReviewStatus(lines[7]);
                }

                readLines.setMemberName(lines[1]);

                try
                {
                    Date date = new SimpleDateFormat("dd-MM-yyyy").parse(lines[2]); 
                    java.sql.Date dateOfBirth = null;
                    readLines.setDateOfBirth(dateOfBirth);;

                    Date date1 = new SimpleDateFormat("dd-MM-yyyy").parse(lines[3]);
                    java.sql.Date dateOfSubmission = null;
                    readLines.setDateOfSubmission(dateOfSubmission);


                }

                catch (Exception e)
                {
                    System.out.println("Date Format is wrong");
                }



                readLines.setProcedureName(lines[4]);
                readLines.setPreReviewStatus(lines[5]);
                readLines.setReviewerName(lines[6]);
                readLines.setReviewStatus(lines[7]);
                readLines.setNotificationMailId(lines[8]);
                readLines.setTATStatus(lines[9]);


                dataList.add(readLines);


            }

            for (excelRead a : dataList)
            {
                if (a.getMemberID().equals(MemberID))
                {
                return a;
            }

        }
        }

        catch (IOException e)

        {
            System.out.printf("IO Exception", e);
        }

        return null;

    }

}

Please find my requirement:

Requirement 1: Provide MemberID and Filpath as input and return member details.
Requirement 2: Update reviewername as John and review status as Pending if MemberID = 1002.
Requirement 3: Set TAT as RED if date of Submission is greater than 10 days from today
               Set TAT as AMBER if date of Submission is greater than 5 days from today
               Set TAT as green if date of Submission is greater than 1 day from today but less than 5 days.
Requirement 4: get member details if review status is approved.
requirement 5: For TAT status as RED update NotificationMailID.[enter link description here][1] Input Filepath, Notification EnailID.

CSV File:

MemberID,MemberName,dateOfBirth,dateOfSubmission,ProcedureName,PreReviewStatus,ReviewerName,ReviewStatus,NotificationMailId,TATStatus
1001,Avanthika,12-01-1989,07-12-2019,X-Ray,Pending,,,,
1002,Reema,03-04-1971,07-12-2019,CT-San,Pending,,,,
1003,Ashoke,14-09-1980,13-07-2019,MRI,Pending,Dave,Approved,,
1003,Francis,02-02-1965,16-07-2019,Blood Test,Pending,John,Rejected,,
Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
  • You are processing requirement 2 before you have read all the lines. – Jonathan Rosenne Jan 04 '20 at 05:58
  • Getting a _java.lang.ArrayIndexOutOfBoundsException: 6_ means that the line you are reading does not have 7 elements but less. Check your input file – P.J.Meisch Jan 04 '20 at 07:04
  • As an aside I recommend you don’t use `SimpleDateFormat` and the two `Date` classes. Those classes are poorly designed and long outdated, the first in particular notoriously troublesome. Instead use `LocalDate` and `DateTimeFormatter`, both from [java.time, the modern Java date and time API](https://docs.oracle.com/javase/tutorial/datetime/). – Ole V.V. Jan 04 '20 at 08:10
  • It’s a pitfall alright. When you split the line `1001,Avanthika,12-01-1989,07-12-2019,X-Ray,Pending,,,,` using `readexcel.split(",")`, you may expect an array of 10 elements, but you get only 6 elements. See the linked original questions for details and for how to fix. – Ole V.V. Jan 04 '20 at 08:42

0 Answers0