• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Uhm, could you tell me where exactly your problem is ?
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?"

 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you'll find line 29 of the Project5Read class is the problem
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you had used proper indentation and {} conventions, you would have seen what Joanne saw much sooner.
 
Radhika Srinivasan
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Radhika Srinivasan
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Radhika Srinivasan
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just initialize counter variable to 1 instead of 0.
 
Radhika Srinivasan
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My project works perfectly fine

Thank you very much

Cheers,
Radhika
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic