This discussion is archived
1 Reply Latest reply: Oct 12, 2009 11:11 PM by 807580 RSS

Help with IOException and looping

807580 Newbie
Currently Being Moderated
Directions:
A local company has decided that they need a program to read employee evaluation data and print out evaluations to be assessed by management. Evaluation data includes the employee name, their title, their department, and their evaluation on the following 6 criteria (1 – strongly disagree, 2 – disagree, 3 – agree, 4 – strongly agree, 5 – very strongly agree).
•     Employee is making a contribution to company goals
•     Employee is knowledgable and properly trained for job
•     Employee is positive and gets along with coworkers
•     Employee is performing weekly duties
•     Employee is present for scheduled meetings
•     Employee is at work on time and stays for their scheduled hours
Evaluation data is stored in a text file that contains data on each line in the following order: first name, last name, title, department, and evaluation for each of the above criteria. This data is stored for multiple employees with a blank line between each set of employee data. An example data file can be found on the course website.
The job of your program is to read in the employees’ information and convert it to separate files for each employee that can be easily read by management. Each output file should be named lastname_firstname.txt in lower case (example: doe_john.txt). The output file should print out the employee’s name, their title, their department, each of the questions with the rating displayed as text, and the average of all 6 ratings. The following page contains an example output file for John Doe.
   import java.io.*;
   import java.util.*;

    public class Evaluation{
       public void createEvaluations() throws IOException{
         
         String inFile = "evaluation_example.txt"; 
         Scanner sc = new Scanner(inFile);
         String last, first, title, department;
         last = sc.nextLine();
         first = sc.nextLine();
         title = sc.nextLine();
         department = sc.nextLine();
         String outFile = last + "_" + first +".txt";
         
         String file_name = (last.toLowerCase() + "_" + first.toLowerCase());
      
         PrintWriter fileOut = new PrintWriter(file_name);
                               
         fileOut.println(first);
         fileOut.println(last);
         fileOut.println(title);
         fileOut.println(department);
              
         fileOut.close();
            
      }
       public String getCriteria(int index){
           
      }
   
       public String getRating(int eval){
      
      }
   }                   
           
Here's as far as I've gotten. So far it's just over my head right now.
  • 1. Re: Help with IOException and looping
    807580 Newbie
    Currently Being Moderated
    String inFile = "evaluation_example.txt"; 
             Scanner sc = new Scanner(inFile);
    you have to give file object to the constructor of the Scanner. Just passing a string with value "evaluation_example.txt" will not work.

    Next time when posting an issue please post the error stack also.