Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can you help me running this program in eclipse and make comments using JAVADOC

ID: 3669258 • Letter: C

Question

Can you help me running this program in eclipse and make comments using JAVADOC comments:

package Desroches.bcs345.hwk.schedule.standalonereport;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.PrintWriter;
import java.util.Scanner;

/**
*
*/

/**
* @author
*
*/
public class ReadFile {

/**
* @param args
*/
@SuppressWarnings("resource")
public static void main(String[] args) {
  Scanner S = new Scanner(System.in);
  System.out.print("Enter input file name:");
  String fileName = S.nextLine();
  try {
   Scanner fileInput = new Scanner(new FileReader(fileName));
   System.out.print("Enter output file name:");
   fileName = S.nextLine();
   PrintWriter outputFile = new PrintWriter(new File(fileName));
   String firstName = fileInput.nextLine();
   String lastName = fileInput.nextLine();
   // The program should always work for a properly formatted input
   // file. You should use a
   // loop to read in the data. Each time through the loop you should
   // process one record from
   // the file (read it in, do any necessary calculations, and write it
   // out). I may test your
   // program with an input file that contains a different number of
   // records then the file you
   // used as input to your program (for example 20 instead of 12). If
   // the program does not
   // work on my input file then it will be marked as incorrect.
   outputFile.println("   Schedule Report");
   outputFile.println("   ---------------");
   outputFile.println();
      outputFile.println("First: "+firstName);
      outputFile.println("Last: "+lastName);
      outputFile.println(" M D    Y Hr Mn Pd Category     Description");
      outputFile.println(" - -    - -- -- -- --------     -----------   ");
   int pmCount=0;
   int amCount=0;
      while (fileInput.hasNextInt()) //
   {
    int Month=fileInput.nextInt();
    int Day= fileInput.nextInt();
    int Year = fileInput.nextInt();
    int Hour = fileInput.nextInt();
    int minute = fileInput.nextInt();
    fileInput.nextLine();
    String period= fileInput.nextLine();
    if(period.equals("PM"))
    {
     pmCount++;
    }
    if(period.equals("AM"))
    {
     amCount++;
    }
    String Category = fileInput.nextLine();
    String Description = fileInput.nextLine();
    outputFile.printf("%02d %02d %4d %02d %02d %2s %-12s %-12s",
      Month,Day,Year ,Hour,minute,period,Category,Description );
    outputFile.println();
   }
   outputFile.println();   
   outputFile.println("Summary");
   outputFile.println("-------");
   outputFile.println("AM appointments: "+amCount);
   outputFile.println("PM appointments: "+pmCount);
   fileInput.close();
   outputFile.close();

  } catch (FileNotFoundException e) {
   e.printStackTrace();
  }

}

}

a) Data: JaneScheduleData.txt

Jane
Smith
2
28
2016
9
30
AM
Work
Full work day today
2
29
2016
10
50
AM
School
Attend HIS 118 World Civilization II
2
29
2016
1
40
PM
School
Attend BCS 345 Java Programming
3
1
2016
1
0
PM
Study
Devoting the day to studying
3
2
2016
11
0
AM
Work
Only working 3 hour shift
3
3
2016
7
0
PM
Recreation
Going to see movie with friends
3
4
2016
1
0
PM
Work
Only a short shift today

b)- JaneScheduleReport.txt

   Schedule Report
   ---------------

First: Jane
Last: Smith
M D    Y Hr Mn Pd Category     Description
- -    - -- -- -- --------     -----------  
02 28 2016 09 30 AM Work         Full work day today
02 29 2016 10 50 AM School       Attend HIS 118 World Civilization II
02 29 2016 01 40 PM School       Attend BCS 345 Java Programming
03 01 2016 01 00 PM Study        Devoting the day to studying
03 02 2016 11 00 AM Work         Only working 3 hour shift
03 03 2016 07 00 PM Recreation   Going to see movie with friends
03 04 2016 01 00 PM Work         Only a short shift today

Summary
-------
AM appointments: 3
PM appointments: 4

Explanation / Answer

Hi, I have corrected your code. It is working fine now.

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

public class ReadFile {
  
   @SuppressWarnings("resource")
   public static void main(String[] args) throws IOException {
   Scanner S = new Scanner(System.in);
   System.out.print("Enter input file name:");
   String fileName = S.nextLine();
   try {
   BufferedReader fileInput = new BufferedReader(new FileReader(fileName));
   System.out.print("Enter output file name:");
   fileName = S.nextLine();
   PrintWriter outputFile = new PrintWriter(new File(fileName));
   String firstName = fileInput.readLine();
   String lastName = fileInput.readLine();
   outputFile.println(" Schedule Report");
   outputFile.println(" ---------------");
   outputFile.println();
   outputFile.println("First: "+firstName);
   outputFile.println("Last: "+lastName);
   outputFile.println(" M D Y Hr Mn Pd Category Description");
   outputFile.println(" - - - -- -- -- -------- ----------- ");
   int pmCount=0;
   int amCount=0;
  
   while (true) //
       {
       String month = fileInput.readLine();
       if(month == null)
           break;
         
           int Month=Integer.parseInt(month);
           int Day= Integer.parseInt(fileInput.readLine());
           int Year = Integer.parseInt(fileInput.readLine());
           int Hour = Integer.parseInt(fileInput.readLine());
           int minute = Integer.parseInt(fileInput.readLine());
           // fileInput.nextLine();
           String period= fileInput.readLine();
           if(period.equals("PM"))
           {
           pmCount++;
           }
           if(period.equals("AM"))
           {
           amCount++;
           }
           String Category = fileInput.readLine();
           String Description = fileInput.readLine();
           outputFile.printf("%02d %02d %4d %02d %02d %2s %-12s %-12s",
           Month,Day,Year ,Hour,minute,period,Category,Description );
         
       outputFile.println();
       }
   outputFile.println();   
   outputFile.println("Summary");
   outputFile.println("-------");
   outputFile.println("AM appointments: "+amCount);
   outputFile.println("PM appointments: "+pmCount);
   fileInput.close();
   outputFile.close();
   } catch (FileNotFoundException e) {
   e.printStackTrace();
   }
   }
}