新网创想网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
public class Test0 {
创新互联公司是一家专注于成都网站制作、网站建设与策划设计,平昌网站建设哪家好?创新互联公司做网站,专注于网站建设十载,网设计领域的专业建站公司;建站业务涵盖:平昌等地区。平昌做网站价格咨询:18980820575
public static void main(String[] args) {
Employee ZhangSan = new Employee("001", "张三", '男', "销售部", 6000, 1000, "普通员工");
Employee LiSi = new Employee("002", "李四", '女', "人事部", 7000, 2000, "超级员工");
System.out.println(ZhangSan.toString()); //打印张三信息
System.out.println(LiSi.toString()); //打印李四信息
}
}
class Employee{
private String id; //员工ID
private String name; //姓名
private char sex; //性别
private String department; //部门
private int basic_salary; //基本工资
private int extra_salary; //薪金
private String classify; //类别
/**
* 构造方法
*/
public Employee(String id, String name, char sex, String department,
int basic_salary, int extra_salary, String classify) {
this.id = id;
this.name = name;
this.sex = sex;
this.department = department;
this.basic_salary = basic_salary;
this.extra_salary = extra_salary;
this.classify = classify;
}
public Employee(){
}
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 char getSex() {
return sex;
}
public void setSex(char sex) {
this.sex = sex;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public int getBasic_salary() {
return basic_salary;
}
public void setBasic_salary(int basic_salary) {
this.basic_salary = basic_salary;
}
public int getExtra_salary() {
return extra_salary;
}
public void setExtra_salary(int extra_salary) {
this.extra_salary = extra_salary;
}
public String getClassify() {
return classify;
}
public void setClassify(String classify) {
this.classify = classify;
}
public String toString(){
String str ="[员工ID:"+id+"|姓名:"+name+"|性别:"+sex+
"|部门:"+department+"|基本工资:+"+basic_salary+
"|薪金:"+extra_salary+"|类别:"+classify+"]";
return str;
}
}
/**
* 职工类
*/
public class Employee {
private String identifier;//职工编号
private String name;//职工姓名
public Employee() {
}
public Employee(String identifier, String name) {
this.identifier = identifier;
this.name = name;
}
public String getIdentifier() {
return identifier;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void work() {
System.out.println("工作时间:周一至周五,朝九晚五");
}
public void showInfo() {
System.out.println("编号:"+getIdentifier()+",姓名:"+getName());
}
}
/**
* 经理类
*/
public class Manager extends Employee{
private String department;//工作部门
public Manager(String identifier, String name) {
super(identifier, name);
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
@Override
public void showInfo() {
System.out.println("编号:"+getIdentifier()+",姓名:"+getName()+",负责的工作部门:"+getDepartment());
}
}
/**
* 董事长类
*/
public class Chairman extends Employee{
@Override
public void work() {
System.out.println("董事长主持召开股东大会");
}
}
/**
* 测试类:类名DemoTest03
*/
public class DemoTest03 {
public static void main(String[] args) {
Employee e = new Employee("07","益达");
Manager m = new Manager("01","小黑");
m.setDepartment("爱情公寓");
Chairman c = new Chairman();
e.showInfo();
e.work();
m.showInfo();
c.work();
}
}
abstract class Person{
private String name;
private String post;
Person(String name,String post){
this.name = name;
this.post = post;
}
public String getID(){
return (name+""+post);
}
public abstract double counting();
public void setName(String name){
this.name = name;
}
public String getName(){
return this.name;
}
public void setPost(String post){
this.post = post;
}
public String getPost(){
return this.post;
}
}
class Leader extends Person{
Leader(String name,String post){
super(name,post);
}
public double counting(){
return 3000d;
}
}
class Management extends Person{
private double basicWage=0d; //基本工资
private double allowance=0d; //津贴
Management(String name,String post){
super(name,post);
}
public void setBasicWage(double basicWage){
this.basicWage = basicWage;
}
public double getBasicWage(){
return this.basicWage;
}
public void setAllowance(double allowance){
this.allowance = allowance;
}
public double getAllowance(){
return this.allowance;
}
public double counting(){
return this.basicWage+this.allowance;
}
}
class Teacher extends Person{
private int hours; //课时
static final double ASSISTANT_STANDARD = 35.0d;//助教的课时收费标准
static final double LECTOR_STANDARD = 45.0d;//讲师的课时收费标准
static final double ANOTHER_STANDARD = 55.0d;//其他课时收费标准
Teacher (String name,String post){
super(name,post);
}
public double counting(){
double wage; //工资
if(this.getPost().equals("助教")){
wage = ASSISTANT_STANDARD*hours;
}else if(this.getPost().equals("讲师")){
wage = LECTOR_STANDARD * hours;
}else{
wage = ANOTHER_STANDARD * hours;
}
return wage;
}
public void setHours(int hours){
this.hours = hours;
}
public int getHours(){
return this.hours;
}
}
class Test {
public static void main(String [] args){
Leader leader = new Leader("张三","领导");
System.out.println(leader.getName()+"工资为:"+leader.counting());
Management manage = new Management("李四","管理人员");
manage.setBasicWage(1000d);
manage.setAllowance(500d);
System.out.println(manage.getName()+"工资为:"+manage.counting());
Teacher teacher = new Teacher("王五","助教");
teacher.setHours(50);
System.out.println(teacher.getName()+"工资为:"+teacher.counting());
Teacher teacher1 = new Teacher("赵六","讲师");
teacher1.setHours(60);
System.out.println(teacher1.getName()+"工资为:"+teacher1.counting
());
}
}
看下吧,有什么不足的请指出来
public class Person {
//(1) 设计一个类 人员,包含三个成员变量:姓名、年龄、性别。
private String name;
private int age;
private String sex;
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 getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
}
//(2) 设计员工和顾客两个类为 人员类的子类,员工类包含一个成员变量:职称级别;顾客包含一个成员变量:账户余额。
class worker extends Person{
private String Title_Level;
public String getTitle_Level() {
return Title_Level;
}
public void setTitle_Level(String title_Level) {
Title_Level = title_Level;
}
}
class Customer extends Person{
private int Account_balance;
public int getAccount_balance() {
return Account_balance;
}
public void setAccount_balance(int account_balance) {
Account_balance = account_balance;
}
}
//(3) 设计一个类 取款机包含两个成员方法:取款,查询账户。
interface ATM{
void Teller(Customer cus);
void Checkaccount(Customer cus);
}
//4) 实现取款机的取款方法,
//当顾客来取钱但是账户余额不足时抛出异常“余额不足”并显示,
//无论取款是否发生异常,最终取款方法需要执行“退卡”操作。
class ATMimpl implements ATM{
public void Checkaccount(Customer cus) {
}
public void Teller(Customer cus) {
}
}
class Employee {//雇员类
int age;
//所有信息
}
class Test{
List list = new ArrayList();
//声明创建五个对象
//比如Employee a = new Employee();
//......a.age = 30;
list.add(a);
//五个对象都加入List集合中
//然后遍历取出,比较年龄
for(int i=0;ilist.size;i++)
{
//取出年龄最大的对象 e
}
//输出e的所有信息
System.out.println(e.age + "其他信息");
}