日期:2014-05-20  浏览次数:20768 次

我是一个初学者,望大家帮助哈我啊!谢谢...
开发一个JAVA应用程序,确定3个雇员中每个人的工资总额.对于每个雇员的前40个小时工作时间,公司按正规工作时间付费,超过40小时之后按一半的工作时间付费.已经给出了公司雇员的清单,上周每个雇员的工作时数以及每个雇员的每小时工作费用标准.程序应该能够输入每个雇员的这些信息,确定并显示雇员的工资总额.使用Scanner类输入数据.

------解决方案--------------------
这是初学者做的题?
------解决方案--------------------
import java.util.*;
import java.io.*;
class XXXX
{
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(
new InputStreamReader(System.in));
Map map = new HashMap();
String line = br.readLine();
while(line != null && !line.equals( " ")){
String[] s = line.split( "\\s+ ");
System.out.println(s[0]);
System.out.println(s[1]);
int hour = Integer.parseInt(s[1]);
if(map.containsKey(s[0])){
((Hour)map.get(s[0])).hour+=hour;
}else{
map.put(s[0],new Hour(hour));
}
line = br.readLine();
}
System.out.println(map);
}
}
class Hour{
int hour;
Hour(int hour){
this.hour = hour;
}
public String toString(){
return " "+hour;
}
}
=============================
这里有个用System.in的例子,你自己参考一下吧。Scanner 差不多,就是用nextLine()
------解决方案--------------------
import java.util.Scanner;

public class SalaryTest {
/**
* @param args
*/
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
for (int i = 1; i <= 3; i++) {
System.out.println( "请输入第 " + i + "个雇员的姓名: ");
String name = in.next();
System.out.println( "该雇员的时薪: ");
double salaryPerHour = in.nextDouble();
System.out.println( "该位雇员本星期工作的小时数: ");
int workTime = in.nextInt();
Employee employee = new Employee();
employee.setName(name);
employee.setSalaryPerHour(salaryPerHour);
employee.setWorkTime(workTime);
employee.setSalary(Employee.accountSalary(salaryPerHour, workTime));
employee.description();
}

}

}

class Employee {
private String name;

private double salary;

private double salaryPerHour;

private int workTime;

public String getname() {
return this.name;
}

public void setName(String name) {
this.name = name;
}

public double getSalary() {
return this.salary;
}

public void setSalary(double salary) {
this.salary = salary;
}

public double getsalaryPerHour() {
return this.salaryPerHour;
}

public void setSalaryPerHour(double salaryPerHour) {
this.salaryPerHour = salaryPerHour;
}
public int getWorkTime(){
return this.workTime;
}
public void setWorkTime(int workTime){
this.workTime = workTime;
}

public void description() {
System.out.println( "雇员名字: " + this.name + " 时薪: "
+ this.salaryPerHour);
System.out.println( "工作时间(时) " + this.workTime
+ "应付工资: " + this.salary);
}
public static double accountSalary(double salaryPerHour, int workTime){
if( workTime <= 40){