重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
public class Employee {
我们提供的服务有:做网站、成都网站设计、微信公众号开发、网站优化、网站认证、沧源ssl等。为上千家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的沧源网站制作公司
private String id; // 员工ID号
private String name; // 姓名
private int age; // 年龄
private boolean sex; // 性别(其中:true表示男,false表示女)
private String phone; // 联系电话
private float salary; // 薪水
Employee(String sId, String sName, int sAge, boolean sSex, String sPhone,
float sSalary) {
this.id = sId;
this.name = sName;
this.age = sAge;
this.sex = sSex;
this.phone = sPhone;
this.salary = sSalary;
}
public String toString() {
return "员工ID号:" + this.id + "\n员工姓名:" + this.name + "\n员工年龄:"
+ this.age + "\n员工性别:" + (this.sex == true ? "男" : "女")
+ "\n联系电话:" + this.phone + "\n薪水:" + this.salary;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public float getSalary() {
return salary;
}
public void setSalary(float salary) {
this.salary = salary;
}
public boolean isSex() {
return sex;
}
public void setSex(boolean sex) {
this.sex = sex;
}
}
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());
}
}
都加上注释了,要是还有啥不懂的 可以继续问我
public class Employee{ private String name;//姓名 private int salary;//薪水
public Employee()
{
//无参构造函数 }
public Employee(String name,int salary)
{ //有参构造函数 this.name=name;
this.salary=salary; //局部变量若与类变量同名,则以局部变量为准,类变量需要用this引用 }
public void setName(String name){
this.name=name; }
public String getName()
{ return this.name;
}
public void setSalary(int salary)
{ this.salary=salary; }
public int getSalary()
{ return this.salary; }}
//测试类
public class Test()
{ public static void main(String args[])
{ Employee e = new Employee("张三",1200);
System.out.println(e.getName());//输出姓名
System.out.println(e.getSalary());//输出薪水
Employee e2= new Employee();
e2.setName("李四");
e.setSalary(1000);
System.out.println(e2.getName());//输出姓名
System.out.println(e2.getSalary());//输出薪水 }
}
*运行结果
张三
1200
李四
1000
*
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;
}
}