public class Test0 {
創(chuàng)新互聯(lián)公司是一家專注于成都網(wǎng)站制作、網(wǎng)站建設(shè)與策劃設(shè)計(jì),平昌網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)公司做網(wǎng)站,專注于網(wǎng)站建設(shè)十載,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:平昌等地區(qū)。平昌做網(wǎng)站價(jià)格咨詢: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; //類別
/**
* 構(gòu)造方法
*/
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("工作時(shí)間:周一至周五,朝九晚五");
}
public void showInfo() {
System.out.println("編號:"+getIdentifier()+",姓名:"+getName());
}
}
/**
* 經(jīng)理類
*/
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()+",負(fù)責(zé)的工作部門:"+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","益達(dá)");
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; //課時(shí)
static final double ASSISTANT_STANDARD = 35.0d;//助教的課時(shí)收費(fèi)標(biāo)準(zhǔn)
static final double LECTOR_STANDARD = 45.0d;//講師的課時(shí)收費(fèi)標(biāo)準(zhǔn)
static final double ANOTHER_STANDARD = 55.0d;//其他課時(shí)收費(fèi)標(biāo)準(zhǔn)
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("張三","領(lǐng)導(dǎo)");
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) 設(shè)計(jì)一個(gè)類 人員,包含三個(gè)成員變量:姓名、年齡、性別。
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) 設(shè)計(jì)員工和顧客兩個(gè)類為 人員類的子類,員工類包含一個(gè)成員變量:職稱級別;顧客包含一個(gè)成員變量:賬戶余額。
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) 設(shè)計(jì)一個(gè)類 取款機(jī)包含兩個(gè)成員方法:取款,查詢賬戶。
interface ATM{
void Teller(Customer cus);
void Checkaccount(Customer cus);
}
//4) 實(shí)現(xiàn)取款機(jī)的取款方法,
//當(dāng)顧客來取錢但是賬戶余額不足時(shí)拋出異?!坝囝~不足”并顯示,
//無論取款是否發(fā)生異常,最終取款方法需要執(zhí)行“退卡”操作。
class ATMimpl implements ATM{
public void Checkaccount(Customer cus) {
}
public void Teller(Customer cus) {
}
}
class Employee {//雇員類
int age;
//所有信息
}
class Test{
List list = new ArrayList();
//聲明創(chuàng)建五個(gè)對象
//比如Employee a = new Employee();
//......a.age = 30;
list.add(a);
//五個(gè)對象都加入List集合中
//然后遍歷取出,比較年齡
for(int i=0;ilist.size;i++)
{
//取出年齡最大的對象 e
}
//輸出e的所有信息
System.out.println(e.age + "其他信息");
}