Get your CodeRanch badge!*
The moose likes Beginning Java and the fly likes I am able to display the file information, but I am having problem displaying the employee details. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "I am able to display the file information, but I am having problem displaying the employee details." Watch "I am able to display the file information, but I am having problem displaying the employee details." New topic
Author

I am able to display the file information, but I am having problem displaying the employee details.

Radhika Srinivasan
Ranch Hand

Joined: Jul 28, 2009
Posts: 32
For this project, you will write a program that allows the user to create a data file and populate that file with information. You will also create an application that allows the user to view the characteristics of the created file. This application will also display the formatted output of the file.

If the user attempts to enter an invalid filename, your program will catch the exception, display a message to the user, & end the program.

To create your first program named Project5Write, which prompts the user to enter the filename. It will then create an input stream for the data using this file.

The program will then need to prompt for an Employee's Name, department, and Number of Vacation Days, and then write the record to the named file. Create the program so that when the user enters "quit" the loop terminated and the file is closed.

Second program for this project will use the file created in the Project5Write to create a formatted report that displays a list of the information in the file you've created. Include a line at bottom that lists the total number of records in the file. Call this program Project5Read. Include a test to return an error if the filename selected doesn't exist.

If the file is valid, your program should display a message that says that the file is valid, the size of the file in bytes, the last time that thr file was modified, and whether the file can be read and written to.





Many thanks,
Radhika
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
Uhm, could you tell me where exactly your problem is ?


JDBCSupport - An easy to use, light-weight JDBC framework -
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10916
    
  12

Posting nothing more than your homework assignment and 110 lines of code will probably not get you much help.

Asking a focused, direct question and posting only the relevant portion of your code would be much better. something like "I have the data in THIS structure, how do I iterate over it?"


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3169
    
  10
I think you'll find line 29 of the Project5Read class is the problem


Joanne
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
If you had used proper indentation and {} conventions, you would have seen what Joanne saw much sooner.
Radhika Srinivasan
Ranch Hand

Joined: Jul 28, 2009
Posts: 32
when I try reading the file say for example "test.dat" which contains the details of employee name, department & number of vacation days. Employee information is not getting displayed wherein, only the following information is getting displayed :

Enter a file name:
test.dat

test.dat is a valid file.
The file is 50 bytes long.
It was last modified on 1013560836000 in Java Standard Time.
The file can be read
The file can be writtten to.

--------------------------------------------------------------------------------------------------

This information is not getting displayed :

The Employee's Number is : 1
The Employee's Name : James Smith
The Employee's Department : Sales
The Employee has 15 Vacation Days Available

The Employee's Number is : 2
The Employee's Name : John Darne
The Employee's Department : Security
The Employee has 20 Vacation Days Available

The total number of Employee is :2

Thanks,
Radhika
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1398
    
    6

I haven't gone through the code fully, but probably the call to system.exit , in case of file does not exist condition, should be within braces.

i.e


should be



other wise even if the file exists, the program will terminate, before entering the loop to display records.

Swastik
Radhika Srinivasan
Ranch Hand

Joined: Jul 28, 2009
Posts: 32
Thank you for the suggestion

After I use the brackets : I received the output this way :

Enter a file name:
test.dat
test.dat is a valid file.
The file is 50 byte long
It was last modified on 1248851551486 in Java Standard Time.
The file can be read.
The file can be written to.
null
java.io.EOFException
at java.io.DataInputStream.readFully(DataInputStream.java:180)
at java.io.DataInputStream.readUTF(DataInputStream.java:592)
at java.io.DataInputStream.readUTF(DataInputStream.java:547)
at Project5Read.main(Project5Read.java:43)

----jGRASP: operation complete.
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1398
    
    6

Radhika Srinivasan
Ranch Hand

Joined: Jul 28, 2009
Posts: 32
Thank you very much

It works but the problem is the employee number it start from "0", I would like to start employee number starting with 1.

----jGRASP: operation complete.

Enter a file name:
test.dat
test.dat is a valid file.
The file is 50 byte long
It was last modified on 1248851551486 in Java Standard Time.
The file can be read.
The file can be written to.

The Employee's Number is: 0
The Employee's Name is: James Smith
The Employee's Department is: Sales
The Employee has 15 Vacation Days Available

The Employee's Number is: 1
The Employee's Name is: John Darme
The Employee's Department is: Security
The Employee has 20 Vacation Days Available
java.io.EOFException
at java.io.DataInputStream.readUnsignedShort(DataInputStream.java:323)
at java.io.DataInputStream.readUTF(DataInputStream.java:572)
at java.io.DataInputStream.readUTF(DataInputStream.java:547)
at Project5Read.main(Project5Read.java:42)
The total number of Employees is: 2

----jGRASP: operation complete.
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1398
    
    6

Just initialize counter variable to 1 instead of 0.
Radhika Srinivasan
Ranch Hand

Joined: Jul 28, 2009
Posts: 32
I've tried it but the total number of employees increases to "3" , which infact should show "2" because I've two employee's.

"the total number of employees : 3"

Thanks,
Radhika
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1398
    
    6

Ok, let it be 0, while displaying add 1

i.e.
System.out.println("The Employee's Number is: " +(counter+1));
Radhika Srinivasan
Ranch Hand

Joined: Jul 28, 2009
Posts: 32
My project works perfectly fine

Thank you very much

Cheers,
Radhika
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I am able to display the file information, but I am having problem displaying the employee details.
 
Similar Threads
Serializing an Object in Java ? How do i reuse it the object and where can i !
totally screwed newbie, need assignment help
unable to exit program..
what is the error in this program
Else without if error