标准格式包含: 私有属性 无参构造 有参构造 setter 和getter 需求中的方法
需求一:
员工类Employee
属性:姓名name,工号id,工资salary
行为:显示所有成员信息的方法show()
需求二:
动物类Animal
属性:姓名name,年龄age
行为:吃饭eat,睡觉sleep
需求三:
人类Person
属性:姓名name,年龄age,性别gender
行为:学习study,睡觉sleep
代码示例:
package cn.zxj.com; import java.math.BigDecimal; /* 员工类Employee 属性:姓名name,工号id,工资salary 行为:显示所有成员信息的方法show() */ public class Employee { private String name; private Integer id; private BigDecimal salary; public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public BigDecimal getSalary() { return salary; } public void setSalary(BigDecimal salary) { this.salary = salary; } public Employee() { } public Employee(String name, Integer id, BigDecimal salary) { this.name = name; this.id = id; this.salary = salary; } public String show() { return "Employee{" + "name='" + name + '\'' + ", id=" + id + ", salary=" + salary + '}'; } }
package cn.zxj.com; import java.math.BigDecimal; public class Test { public static void main(String[] args){ Employee e = new Employee("xiaowang", 10, new BigDecimal("25000")); System.out.println(e.show()); } }