扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
public class Employee {
目前累计服务客户上千多家,积累了丰富的产品开发及服务经验。以网站设计水平和技术实力,树立企业形象,为客户提供网站制作、成都做网站、网站策划、网页设计、网络营销、VI设计、网站改版、漏洞修补等服务。创新互联公司始终以务实、诚信为根本,不断创新和提高建站品质,通过对领先技术的掌握、对创意设计的研究、对客户形象的视觉传递、对应用系统的结合,为客户提供更好的一站式互联网解决方案,携手广大客户,共同发展进步。
private int id;
private byte sex;
private String name;
private String duty;
private float salary;
private int holidays;
public Employee(int id,byte sex,String name,String duty, float salary,int holidays){
this.id = id;
this.sex = sex;
this.name = name;
this.duty = duty;
this.salary = salary;
this.holidays = holidays;
}
public String getDuty() {
return duty;
}
public void setDuty(String duty) {
this.duty = duty;
}
public int getHolidays() {
return holidays;
}
public void setHolidays(int holidays) {
this.holidays = holidays;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getSalary() {
return salary;
}
public void setSalary(float salary) {
this.salary = salary;
}
public byte getSex() {
return sex;
}
public void setSex(byte sex) {
this.sex = sex;
}
/**
* display(),无返回值,该方法能打印员工的姓名、性别以及职务
* @param employee
*/
public void display(Employee employee){
System.out.println("员工姓名为: " + employee.getName());
if(employee.getSex()==1){
System.out.println("员工性别为: 男 ");
}else if(employee.getSex()==2){
System.out.println("员工性别为:女 ");
}
System.out.println("员工职务为: " + employee.getDuty());
}
/**
* getDecMoney(int day) 返回值是int型。
* 如果请假天数=3,则扣款为30×请假天数;
* 如果请假天数超过3天,则扣款为50×请假天数。
* @param day
* @return
*/
public int getDecMoney(int day){
int deduction = 0; //扣除的工资
if(day = 3){
deduction = 30*day;
}else if(day 3){
deduction = 50*day;
}
return deduction;
}
public static void main(String[] args){
//创建一个员工类的对象
Employee employee = new Employee(123456789,(byte) 1,"陈冠希","生产帽子的(绿色)",(float) 500.8,5);
employee.display(employee); //调用display()
int deduction = employee.getDecMoney(employee.getHolidays());//调用getDecMoney()
System.out.println("该员工因请假扣除工资" + deduction + "元");
}
}
public class Test{
//此示例代码我只添加了两个员工、两个部门,仅供参考
public static void main(String[] args) {
Dept d1 = new Dept();
d1.setDeptId(1);
d1.setDeptName("财务部");
Dept d2 = new Dept();
d2.setDeptId(2);
d2.setDeptName("技术部");
Emp e1 = new Emp();
e1.setEmpId(1);
e1.setEmpName("张三");
Emp e2 = new Emp();
e2.setEmpId(2);
e2.setEmpName("李四");
e1.setDept(d1);
e2.setDept(d2);
}
}
class Dept{
private Integer deptId;
private String deptName;
public void setDeptId(Integer deptId){
this.deptId = deptId;
}
public Integer getDeptId(){
return deptId;
}
public void setDeptName(String deptName){
this.deptName = deptName;
}
public String getDeptName(){
return deptName;
}
}
class Emp{
private Integer empId;
private String empName;
private Dept dept;
public void setEmpId(Integer empId){
this.empId = empId;
}
public Integer getEmpId(){
return empId;
}
public void setEmpName(String empName){
this.empName = empName;
}
public String getEmpName(){
return empName;
}
public void setDept(Dept dept){
this.dept = dept;
}
public Dept getDept(){
return dept;
}
}
package com.test;
public class Employee {
private String name;
private int id;
private String address;
private double salary;
public Employee(){ //无参构造器
}
public Employee(String name,int id,String address,double salary){ //构造器
this.name = name;
this.id = id;
this.address = address;
this.salary = salary;
}
public double js(){ //计算工资的方法
return 0;
}
public String print() { //输出员工基本信息
return "姓名:" + name + " 职工号:" + id + " 地址:" + address;
}
public String getName() { //对一些属性的设置和修改方法
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public static void main(String[] args) {
ZsEmp z = new ZsEmp();
z.setName("正式员工");
z.setId(1001);
z.setAddress("China");
LsEmp l = new LsEmp();
l.setName("临时员工");
l.setId(1002);
l.setAddress("China");
Employee[] emps = new Employee[2];
emps[0] = z;emps[1] = l;
for(Employee e : emps){
System.out.println(e.print()+",他的工资:"+e.js());
}
}
}
class ZsEmp extends Employee{ //正式员工
@Override
public double js() {
double s = 3000; //不知道具体的计算方法是怎样,这里简单写了
return s;
}
}
class LsEmp extends Employee{ //临时员工
@Override
public double js() {
double s = 1000;
return s;
}
}
package jsoft.portal.yjdd;
import java.util.Scanner;
public class Demo {
private String name="joe";
private int age=18;
private String salary="7500rmb";
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getSalary() {
return salary;
}
public void setSalary(String salary) {
this.salary = salary;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//显示年龄、显示姓名、获取工资
Demo d= new Demo();
System.out.println("年龄 :"+d.getAge());
System.out.println("姓名 :"+d.getName());
System.out.println("工资 :"+d.getSalary());
//修改 姓名
//读取控制台 输入字符
Scanner sc= new Scanner(System.in);
String name= sc.next();
d.setName(name);
//显示 修改后 名字
System.out.println("修改后的姓名为 :"+d.getName());
}
}
都加上注释了,要是还有啥不懂的 可以继续问我
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流