191 - 员工的工资
Time Limit: 1000 Memory Limit: 65535
Submit: 58 Solved: 13
Description
假定要为某个公司编写雇员工资支付程序,这个公司有各种类型的雇员(Employee),不同类型的雇员按不同的方式支付工资(都是整数): (1)经理(Manager)——每月获得一份固定的工资 (2)销售人员(Salesman)——在基本工资的基础上每月还有销售提成 (3)一般工人(Worker)——则按他每月工作的天数计算工资 在Employee中提供方法getSalary(),用于计算每个雇员一个月的工资,并在子类中重写。 Post_AppendCode的main方法中已经构造Employee的三个变量,分别指向Manager、Salesman、Worker的对象,调用getSalary方法,输出三个对象的工资。 要求:编码实现经理、销售人员、一般工人三个类。
Input
经理的月工资 销售人员的基本工资 销售人员的提成 工人的工作天数 工人每天的工资
Output
经理的工资 销售人员的工资 工人的工资
Sample Input
12000 3000 5000 22 200
Sample Output
12000 8000 4400
Post Append Code
public class Main{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int managerSalary = scan.nextInt();
int salemanSalary = scan.nextInt();
int salemanRaise = scan.nextInt();
int workerEveryday = scan.nextInt();
int workerDays = scan.nextInt();
Employee e1 = new Manager(managerSalary);
Employee e2 = new Salesman(salemanSalary, salemanRaise);
Employee e3 = new Worker(workerEveryday, workerDays);
System.out.println(e1.getSalary());
System.out.println(e2.getSalary());
System.out.println(e3.getSalary());
scan.close();
}
}
答案:
package 学生大学生研究生类;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
int no = scan.nextInt();
String name = scan.next();
String sex = scan.next();
Student s = new Student(no, name, sex);
s.print();
no = scan.nextInt();
name = scan.next();
sex = scan.next();
String major = scan.next();
CollegeStudent c = new CollegeStudent(no, name, sex, major);
c.print();
no = scan.nextInt();
name = scan.next();
sex = scan.next();
major = scan.next();
String supervisor = scan.next();
GraduateStudent g = new GraduateStudent(no, name, sex, major, supervisor );
g.print();
g.doResearch();
scan.close();
}
}
class Student
{
int no;
String name;
String gender;
public Student(int _no, String n, String g) {
this.no = _no;
this.name = n;
this.gender = g;
}
public int getNo() {
return no;
}
public void setNo(int no) {
this.no = no;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public void print()
{
System.out.println("no: "+getNo());
System.out.println("name: "+getName());
System.out.println("sex: "+getGender());
}
}
class CollegeStudent extends Student
{
String major;
public CollegeStudent(int _no, String n, String g, String major) {
super(_no, n, g);
this.major = major;
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
public void print()
{
super.print();
System.out.println("major: "+getMajor());
}
}
class GraduateStudent extends CollegeStudent
{
String supervisor;//导师
public GraduateStudent(int _no, String n, String g, String major, String supervisor) {
super(_no, n, g, major);
this.supervisor = supervisor;
}
public String getSupervisor() {
return supervisor;
}
public void setSupervisor(String supervisor) {
this.supervisor = supervisor;
}
public void doResearch()
{
System.out.println(getName()+" is doing research");
}
public void print(){
super.print();
System.out.println("supervisor: "+supervisor);
}
}