class?Employee?{
成都創(chuàng)新互聯(lián)公司10多年企業(yè)網(wǎng)站制作服務(wù);為您提供網(wǎng)站建設(shè),網(wǎng)站制作,網(wǎng)頁設(shè)計(jì)及高端網(wǎng)站定制服務(wù),企業(yè)網(wǎng)站制作及推廣,對(duì)成都攪拌罐車等多個(gè)方面擁有多年的網(wǎng)站營銷經(jīng)驗(yàn)的網(wǎng)站建設(shè)公司。
private?String?name;
private?String?department;
private?double?salary;
//構(gòu)造方法
public?Employee(String?name,?String?department,?double?salary)?{
this.name?=?name;
this.department?=?department;
this.salary?=?salary;
}
public?String?toString()?{
return?"姓名:"?+?name?+?"\t部門:"?+?department?+?"\t工資:"?+?salary;
}
public?void?raiseSalary(double?per)?{
this.salary?=?salary?+?salary?*?per;
}
public?String?getName()?{
return?name;
}
public?void?setName(String?name)?{
this.name?=?name;
}
public?String?getDepartment()?{
return?department;
}
public?void?setDepartment(String?department)?{
this.department?=?department;
}
public?double?getSalary()?{
return?salary;
}
public?void?setSalary(double?salary)?{
this.salary?=?salary;
}
}
public?class?TestEmployee?{//測(cè)試類
public?static?void?main(String[]?args)?{
Employee?e1?=?new?Employee("張三",?"技術(shù)開發(fā)部",?5000);
Employee?e2?=?new?Employee("趙四",?"后勤服務(wù)部",?3800);
Employee?e3?=?new?Employee("王五",?"產(chǎn)品營銷部",?6800);
System.out.println(e1?+?"\n"?+?e2?+?"\n"?+?e3);
double?per?=?0.07;
e1.raiseSalary(per);
e2.raiseSalary(per);
e3.raiseSalary(per);
System.out.println("==============加薪7%===============");
System.out.println(e1?+?"\n"?+?e2?+?"\n"?+?e3);
}
}
輸出
姓名:張三 部門:技術(shù)開發(fā)部 工資:5000.0
姓名:趙四 部門:后勤服務(wù)部 工資:3800.0
姓名:王五 部門:產(chǎn)品營銷部 工資:6800.0
==============加薪7%===============
姓名:張三 部門:技術(shù)開發(fā)部 工資:5350.0
姓名:趙四 部門:后勤服務(wù)部 工資:4066.0
姓名:王五 部門:產(chǎn)品營銷部 工資:7276.0
import?java.util.Arrays;
class?YG?implements?ComparableYG{//員工類,實(shí)現(xiàn)比較接口
String?name;//姓名
int?gz;//工資
public?YG(String?name,?int?gz)?{
this.name?=?name;
this.gz?=?gz;
}
public?String?toString()?{
return?"姓名:"+name+"\t工資:"+gz;
}
public?int?compareTo(YG?o)?{//通過這個(gè)方法,?實(shí)現(xiàn)按工資排序
return?o.gz-this.gz;//從大到小
}
}
public?class?MyTest?{
public?static?void?main(String[]?args)?{
YG[]?ary?=?new?YG[5];
ary[0]?=?new?YG("張三",?5260);
ary[1]?=?new?YG("趙四",?6000);
ary[2]?=?new?YG("王五",?5500);
ary[3]?=?new?YG("唐六",?5800);
ary[4]?=?new?YG("楊七",?5200);
Arrays.sort(ary);//排序
double?sum?=?0;
for?(YG?yg?:?ary)?{
sum+=yg.gz;
}
System.out.println("最高工資:"+ary[0]+"\n平均工資:"+sum/ary.length);
}
}
輸出
最高工資:姓名:趙四 工資:6000
平均工資:5552.0
一:將員工姓名、工資封裝成一個(gè)對(duì)象
public class Staff {
private String name;
private int salary;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
public Staff(String name, int salary) {
super();
this.name = name;
this.salary = salary;
}
}
二:初始化一個(gè)數(shù)組,算平均工資
public class Average {
public static void main(String[] args) {
Staff staffs[] = {new Staff("zhangsan", 1000), new Staff("lisi", 1100), new Staff("wangwu", 1200)};
int sum = 0;
for(Staff staff : staffs) {
sum = sum + staff.getSalary();
}
System.out.println("員工人數(shù):" + staffs.length + " 總工資:" + sum + " 平均工資:" + sum / staffs.length);
}
}
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
());
}
}
看下吧,有什么不足的請(qǐng)指出來