Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

using PrintWriter and file classes in java

I am to Modify the source code to write output to a user specified file rather than the console/keyboard. I am unsure how to do this any help will be appreciated.

I am also getting the following error...

Employee.java:65: reached end of file while parsing } ^ 1 error

----jGRASP wedge2: exit code for process is 1. ----jGRASP: operation complete.


Employee.java
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.PrintWriter
import java.io.file;
class Employee
{
    private int id;
    private String name, designation;
    private float salary;

    public void getData() throws IOException
    {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        System.out.println ("---Enter Employee Data---");
        System.out.print ("ID? ");
        id = Integer.parseInt(in.readLine());
        System.out.print("Name? ");
        name = in.readLine();
        System.out.print("Designation: ");
        designation = in.readLine();
        System.out.print("Salary: ");
        salary = Float.parseFloat(in.readLine());
        System.out.println("------------------------");
    }
    public void showData()
    {
        System.out.println("-------------------");
        System.out.println("ID: "+id);
        System.out.println("Name: "+name);
        System.out.println("Designation: "+designation);
        System.out.println("Salary: "+ salary);
    }
}
EmployeeRecords.java
class EmployeeRecords
{
    public static void main(String args[]) throws IOException
    {
        BufferedReader in;
        in = new BufferedReader(new InputStreamReader(System.in));

        System.out.print ("How many employees? : ");
        final int n;
        n = Integer.parseInt(in.readLine());

        Employee N[] = new Employee[n];
        for (int i=0; i<n; i++)
        {
            N[i] = new Employee();
        }

        for (int i=0; i<n; i++)
        {
            System.out.println ("Entry no. "+(i+1)+"/"+n);
            N[i].getData();
        }

        System.out.println("===OUTPUT===");
        System.out.println("-------------");

        for (int i=0; i<n; i++)
        {
            N[i].showData();
        }
    }

here is the code again.. I don't know why it is not formatting correctly above.

Employee.java
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.PrintWriter
import java.io.file;
class Employee
{
    private int id;
    private String name, designation;
    private float salary;

    public void getData() throws IOException
    {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        System.out.println ("---Enter Employee Data---");
        System.out.print ("ID? ");
        id = Integer.parseInt(in.readLine());
        System.out.print("Name? ");
        name = in.readLine();
        System.out.print("Designation: ");
        designation = in.readLine();
        System.out.print("Salary: ");
        salary = Float.parseFloat(in.readLine());
        System.out.println("------------------------");
    }
    public void showData()
    {
        System.out.println("-------------------");
        System.out.println("ID: "+id);
        System.out.println("Name: "+name);
        System.out.println("Designation: "+designation);
        System.out.println("Salary: "+ salary);
    }
}
EmployeeRecords.java
class EmployeeRecords
{
    public static void main(String args[]) throws IOException
    {
        BufferedReader in;
        in = new BufferedReader(new InputStreamReader(System.in));

        System.out.print ("How many employees? : ");
        final int n;
        n = Integer.parseInt(in.readLine());

        Employee N[] = new Employee[n];
        for (int i=0; i<n; i++)
        {
            N[i] = new Employee();
        }

        for (int i=0; i<n; i++)
        {
            System.out.println ("Entry no. "+(i+1)+"/"+n);
            N[i].getData();
        }

        System.out.println("===OUTPUT===");
        System.out.println("-------------");

        for (int i=0; i<n; i++)
        {
            N[i].showData();
        }
    }