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

Why this program cannot run in Java Eclipse: ReadFile.java package readfile; imp

ID: 3667504 • Letter: W

Question

Why this program cannot run in Java Eclipse:

ReadFile.java

package readfile;

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

public class ReadFile {

@SuppressWarnings({ "resource", "unused" })
public static void main(String[] args) {
// TODO Auto-generated method stub

Scanner S = new Scanner(System.in);
System.out.print("Enter input file name:");
String fileName = S.nextLine();
try {
Scanner fileInput = new Scanner(new File("JaneScheduleData.txt"));
System.out.print("Enter output file name:");
fileName = S.nextLine();
PrintWriter outputFile = new PrintWriter(new File("JaneScheduleReport.txt"));
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);

outputFile.close();

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

}

public void openFile() {
// TODO Auto-generated method stub

}

public void readFile() {
// TODO Auto-generated method stub

}

public void closeFile() {
// TODO Auto-generated method stub

}

}

JaneFile.java

package readfile;

public class JaneFile {

public static void main(String[] args) {
// TODO Auto-generated method stub

ReadFile S = new ReadFile();
S.openFile();
S.readFile();
S.closeFile();

}

}

Text file 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

Text file 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

You only need to run the ReadFile.java file. There is no need for the JaneFile.java

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
public class ReadFile {
   @SuppressWarnings({ "resource", "unused" })
   public static void main(String[] args) {
       // TODO Auto-generated method stub
       Scanner S = new Scanner(System.in);
       System.out.print("Enter input file name:");
       String fileName = S.nextLine();
       try {
           Scanner fileInput = new Scanner(new File(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);
           outputFile.close();
       } catch (FileNotFoundException e) {
           e.printStackTrace();
       }
   }
   public void openFile() {
       // TODO Auto-generated method stub
   }
   public void readFile() {
       // TODO Auto-generated method stub
   }
   public void closeFile() {
       // TODO Auto-generated method stub
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote