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

My code has four errors and I cannot figure out how to fix them. The error messa

ID: 3757900 • Letter: M

Question

My code has four errors and I cannot figure out how to fix them. The error message says "cannot find symbol." How do I correct this issue?

/*
* File: ChristmasAdventCalendarFile.java
* Author: Melissa Oller
* Date: October 28, 2015
* Purpose: The purpose of this program is to read data from a file.
*/

//import java.io.*;
import java.util.Scanner;

public class ChristmasAdventCalendarFile{

   public static void main(String[] args){

       // integer counter set to default
       int counter = 0;

       // use try and catch method in case of error
       try{
           // use File() method to get the data file
           File inputFile = new File("ChristmasAdventCalendar.txt");

           // define scanner to get the data file
           Scanner fileScanner = new Scanner(inputFile);  

           while(fileScanner.hasNext()){
               System.out.println(fileScanner.next());
               counter ++;
       }
       }
       catch(FileNotFoundException fileNotFound){
       System.out.println("File was not found.");
       }

       // display the counter for numbers of data read
       System.out.println(counter + " data were read.");

       }
  
       // closeFile() to close the data file
       public void closeFile(){
       read.close();
       }

}          

Explanation / Answer

package mani;
//import java.io.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class ChristmasAdventCalendarFile{
public static void main(String[] args){
// integer counter set to default
int counter = 0;
// use try and catch method in case of error
try{
// use File() method to get the data file
File inputFile = new File("C:\Users\MANIKANTA Reddy\Desktop\chegg\ChristmasAdventCalendar.txt");
// define scanner to get the data file
Scanner fileScanner = new Scanner(inputFile);
while(fileScanner.hasNext()){
System.out.println(fileScanner.next());
counter ++;
}
closeFile(fileScanner);
}
catch(FileNotFoundException fileNotFound){
System.out.println("File was not found.");
}
// display the counter for numbers of data read
System.out.println(counter + " data were read.");
}
  
// closeFile() to close the data file
public static void closeFile(Scanner read){

           read.close();
}
}

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