Java编程问题帮助 [英] Java programming problem help

查看:84
本文介绍了Java编程问题帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

分配说明:
应该创建一个Java程序来读取员工文本文件(Information.txt)和
从员工编号中决定并转移哪个部门和员工是谁
已分配.员工列表及其信息应在监视器上显示为
以及写入名为Department.txt的文本文件.
创建一个名为Employee的类,包括一个构造函数和必要的访问器,以及
mutator方法.该类应在字段中保留以下信息:
o员工姓名
o员工编号,格式为NNN-X,其中每个N是一个数字,而X是一个
字母,可以是以下其中之一:
·H-代表人力资源
·A-代表会计
·P-表示生产
·S-表示运输
o雇用日期
接下来,编写一个名为ProductionWorker的类,该类继承自Employee类.包括
构造函数以及必要的访问器和更改器方法. ProductionWorker类
应该在字段中保留以下信息:
o Shift Number,它是一个整数,可以是下列之一:
·1-代表晨班
·2-表示摇摆移位
·3-表示夜班
o每小时工资率
输入:输入文件将命名为Information.txt.一条记录(一行)将包含
员工姓名,员工编号,雇用日期,轮班编号和薪水率,每个均由
分隔 空格.下面是一个示例文本文件.
简·里弗斯902-A 05/16/2001 1 16.25
鲍勃·考克斯(Bob Cox)823-S 1990年6月21日2 17.50
Ann Ramsey 715-A 1998年2月12日1 16.25
约瑟夫·钱德勒723-P 2000/12/22 3 14.35
阿诺德·肯尼迪133-S 1999年10月10日2 18.20
拉里·胡伯(Larry Huber)198-P 2000年12月12日3 17.25
安妮特·威尔逊(Annette Wilson)501-H 1995年4月4日1 20.25
罗伯特·弗格森674-H 2002年4月10日2 16.50
Ava Gaines 434-H 2000年1月5日3 15.65
输出:输出应包含员工姓名,员工编号,
的清单 员工的部门,雇用日期,轮班名称和薪水率此信息应为
显示在监视器上,并写入名为Department.txt的文本文件.

我已经完成了Employee类和ProductionWorker类,但是其余的都存在问题.任何帮助表示赞赏.
这是我到目前为止所拥有的.
以下是Employee类的代码:

01公共班级员工
02 {
03 private String EmployeeName,EmployeeNumber,HireDate;
04
05 public void setEmployeeName(String e)
06 {
07 EmployeeName = e;
08}
09 public void setEmployeeNumber(String n)
10 {
11 EmployeeNumber = n;
12}
13 public void setHireDate(字符串h)
14 {
15 HireDate = h;
16}
17公共字符串getEmployeeName()
18 {
19返回EmployeeName;
20}
21公共字符串getEmployeeNumber()
22 {
23返回EmployeeNumber;
24}
25个公共字符串getHireDate()
26 {
27返回HireDate;
28}
29
30
31}
ProductionWorker代码:
01公共类ProductionWorker扩展了Employee
02 {
03 private int ShiftNumber;
04私人双HourlyPayRate;
05
06 public void setShiftNumber(int s)
07 {
08 ShiftNumber = s;
09}
10公共无效setHourlyPayRate(double h)
11 {
12 HourlyPayRate = h;
13}
14 public int getShiftNumber()
15 {
16返回ShiftNumber;
17}
18个公共double getHourlyPayRate()
19 {
20返回HourlyPayRate;
21}
22
23}

Assignment Description:
A Java program should be created to read an employee text file (Information.txt) and
decide from the employee number and shift which department and shift the employee is
assigned. A list of the employees and their information should be listed to the monitor as
well as written to a text file named Department.txt.
Create a class named Employee including a constructor and the necessary accessor and
mutator methods. The class should keep the following information in fields:
o Employee Name
o Employee Number in the format NNN-X, where each N is a digit and X is a
letter which can be one of the following:
· H - represents Human Resources
· A - represents Accounting
· P - represents Production
· S - represents Shipping
o Hire Date
Next, write a class named ProductionWorker that inherits from the Employee class. Include
a constructor and the necessary accessor and mutator methods. The ProductionWorker class
should keep the following information in fields:
o Shift Number which is an integer and can be one of the following:
· 1 - represents Morning Shift
· 2 - represents Swing Shift
· 3 - represents Night Shift
o Hourly Pay Rate
Input: The input file will be named Information.txt. One record (line) will contain the
employee name, employee number, hire date, shift number and pay rate each separated by
spaces. A sample text file is below.
Jane Rivers 902-A 05/16/2001 1 16.25
Bob Cox 823-S 06/21/1990 2 17.50
Ann Ramsey 715-A 02/12/1998 1 16.25
Joseph Chandler 723-P 12/22/2000 3 14.35
Arnold Kennedy 133-S 08/10/1999 2 18.20
Larry Huber 198-P 02/12/2000 3 17.25
Annette Wilson 501-H 04/04/1995 1 20.25
Robert Ferguson 674-H 04/10/2002 2 16.50
Ava Gaines 434-H 01/05/2000 3 15.65
Output: Output should consist of a listing of the employee name, employee number,
employee''s department, hire date, shift name and pay rate This information should be
displayed on the monitor as well as written to a text file named Department.txt.

I have the Employee class and the ProductionWorker class done but am having problems with the rest. any help is appreciated.
here is what I have so far.
Here is the code for the Employee Class:

01 public class Employee
02 {
03 private String EmployeeName, EmployeeNumber, HireDate;
04
05 public void setEmployeeName(String e)
06 {
07 EmployeeName=e;
08 }
09 public void setEmployeeNumber(String n)
10 {
11 EmployeeNumber=n;
12 }
13 public void setHireDate (String h)
14 {
15 HireDate=h;
16 }
17 public String getEmployeeName()
18 {
19 return EmployeeName;
20 }
21 public String getEmployeeNumber()
22 {
23 return EmployeeNumber;
24 }
25 public String getHireDate()
26 {
27 return HireDate;
28 }
29
30
31 }
ProductionWorker Code:
01 public class ProductionWorker extends Employee
02 {
03 private int ShiftNumber;
04 private double HourlyPayRate;
05
06 public void setShiftNumber(int s)
07 {
08 ShiftNumber=s;
09 }
10 public void setHourlyPayRate(double h)
11 {
12 HourlyPayRate=h;
13 }
14 public int getShiftNumber()
15 {
16 return ShiftNumber;
17 }
18 public double getHourlyPayRate()
19 {
20 return HourlyPayRate;
21 }
22
23 }

推荐答案

考虑使用Scanner对象从文本文件中获取数据.考虑使用Collection类之一来存储数据记录的列表或数组.

这是Scanner类的简介:
http://beginwithjava.blogspot.com/2008/07/getting- keyboard-input-for-console-apps.html [ ^ ]
它使用扫描仪读取键盘,但是可以将扫描仪设置为读取文件.
以下是有关收藏的一些信息:
http://beginwithjava.blogspot.com/search/label/collection [
Consider using a Scanner object to get the data from the text file. Consider using one of the Collection classes to store a list or array of your data records.

Here''s an introduction to the Scanner class:
http://beginwithjava.blogspot.com/2008/07/getting-keyboard-input-for-console-apps.html[^]
It uses the Scanner to read the keyboard, but the Scanner can be set up to read a file instead.
Here is some information on Collections:
http://beginwithjava.blogspot.com/search/label/collection[^]

Good luck on your assignment.


这也是我正在努力但遇到的问题
here is also what im working on but am having problems with it
import java.io.*; 
import java.scanner;
import java.util.StringTokenizer;
public class Employees
	{
		String line, inFile="Information.txt", outFile="Department.txt";
		StringTokenizer tokens;
		File file=new File(filename);
	
		//build input stream
		FileReader fr = new FileReader (inFile);
		BufferedReader fileIn = new BufferedReader (fr);
		
		
		//build output stream
		FileWriter fw = new FileWriter (outFile);
		BufferedWriter bw = new BufferedWriter (fw);
		PrintWriter fileOut = new PrintWriter (bw);
		
		line = fileIn.readLine();
		while (line != null)
		{
			tokens = new StringTokenizer(line);
			employeeName = null;
			employeeNumber = null;
			hireDate = null;
			
			employeeName = tokens.nextToken();
			employeeNumber = tokens.nextToken();
			hireDate = tokens.nextToken();
			
			line = fileIn.readLine();
	}
			fileIn.close();
			fileOut.close();
		
		
	}


作业说明"-这是您的老师希望您自己做的第一个线索.您所做的几乎没有任何事情,定义具有某些属性的类没有涉及任何真正的编程.因此,您并不是真的要说这是我尝试过的,但是我被困住了".您现在所说的是我不知道我在做什么".这是您应该告诉您的老师的内容,以便他可以为您提供建议和/或评估您是否有能力继续他的课程.您还应该假设您的老师足够聪明,可以使用google.您用谷歌搜索家庭作业问题,然后查看发现的内容.我知道您没有使用您的真实姓名,但是他至少会知道他班上的SOMEONE正在试图作弊.
"Assignment description" - this is your first clue that your teacher expects you to do this yourself. What you have done is close to nothing, there''s no real programming involved in defining a class with some properties. Therefore, you''re not really at a point to say ''this is what I''ve tried, but I am stuck''. What you''re saying right now is ''I have no idea what I am doing''. This is something you should tell your teacher, so he can advise you, and/or assess if you''re capable of continuing his course. You should also assume your teacher is smart enough to use google. You google your homework question and see what you find. I see you''ve not used your real name, but he will at least know SOMEONE in his class is trying to cheat.


这篇关于Java编程问题帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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