如何从.dat文件读取值,计算它,然后写入另一个.dat文件 [英] How do I read values from a .dat file, compute it, then write to another .dat file

查看:281
本文介绍了如何从.dat文件读取值,计算它,然后写入另一个.dat文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天,

我正在尝试编写一个java程序,它将从名为Employee.dat的文件中获取信息,程序应该从数据中计算每个Employee的总薪水。文件。然后它应该将结果写入另一个文件名Salary.dat。



Employee.dat就是这种形式



员工姓名等级基本年龄

Juliet Ibrahim 6 32 34,000

Abbey George 8 46 60,000

Kayode Banjoko 9 53 74,000

Umoh Emeh 3 21 20,000



Salary.dat应为此格式



员工姓名总薪资额

Juliet Ibrahim 45,000

Abbey George 70,000





在计算总薪资(GS)时,以下津贴应加到基本工资(BS)中:

1.如果年级大于7,则BS的10%是添加到GS。

2.如果年龄大于50,也会将5%的BS添加到GS。



我真的这样做计算总薪水没有问题,我在哪里挑战是检索信息。从Employee.dat文件,并能够将GS写入Salary.dat文件。



如果有人可以提供解决类似问题的链接,我我也很欣赏。这不是完整的问题,但是一旦我能够掌握这一点,我就可以解决更广泛的问题。



问候。



我尝试了什么:



我有一个不包含使用的工作程序of files。

Good day,
I am trying to write a java program that will get info from a file named Employee.dat, the program should calculate the gross salaries of each of the Employee from the data in the file. It should then write the result to another file names Salary.dat.

Employee.dat is in this form

EMPLOYEE NAME GRADE LEVEL AGE BASIC SALARY
Juliet Ibrahim 6 32 34,000
Abbey George 8 46 60,000
Kayode Banjoko 9 53 74,000
Umoh Emeh 3 21 20,000

Salary.dat should be in this form

EMPLOYEE NAME GROSS SALARY
Juliet Ibrahim 45,000
Abbey George 70,000


In calculating the gross salaries(GS), the following allowances are to be added to the basic salary(BS):
1. If grade level is greater than 7, 10% of the BS is added to GS.
2. If age is greater than 50, 5% of BS is also added to GS.

I really do not have a problem with calculating the gross salaries, where I am having challenge is retrieving info. from Employee.dat file and being able to write the GS into the Salary.dat file.

If anyone can provide me with a link that solves a similar problem, I'd appreciate that too. This is not the full problem, but once I can get my hands on this I will be able to work on the broader problem.

Regards.

What I have tried:

I have a working program that does not incorporate the use of files.

推荐答案

请参阅课程:基本I / O(Java& trade; Tutorials& gt; Essential Classes) [ ^ ]有关文件I / O的完整详细信息。
See Lesson: Basic I/O (The Java™ Tutorials > Essential Classes)[^] for full details on file I/O.


这篇关于如何从.dat文件读取值,计算它,然后写入另一个.dat文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆