class?Employee?{
創(chuàng)新互聯(lián)專注于東阿企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè)公司,商城網(wǎng)站建設(shè)。東阿網(wǎng)站建設(shè)公司,為東阿等地區(qū)提供建站服務(wù)。全流程定制網(wǎng)站制作,專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)
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?{//測試類
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
前幾周回答過類似的問題,, 參考代碼如下
class?Employee?{
private?String?name;
private?double?salary;
//構(gòu)造方法
public?Employee(String?name,?double?salary)?{
this.name?=?name;
this.salary?=?salary;
}
public?String?toString()?{
return?"姓名:"?+?name?+?"\t工資:"?+?salary;
}
public?void?raiseSalary(double?per)?{//加薪的方法
this.salary?=?salary?+?salary?*?per;
}
//屬性的?set?get方法
public?String?getName()?{
return?name;
}
public?void?setName(String?name)?{
this.name?=?name;
}
public?double?getSalary()?{
return?salary;
}
public?void?setSalary(double?salary)?{
this.salary?=?salary;
}
}
public?class?TestEmployee?{//測試類
public?static?void?main(String[]?args)?{
Employee?e1?=?new?Employee("張三",?2000);
Employee?e2?=?new?Employee("李四",?3000);
Employee?e3?=?new?Employee("王五",?4000);
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);
}
}
輸出
姓名:張三 工資:2000.0
姓名:李四 工資:3000.0
姓名:王五 工資:4000.0
==============加薪7%===============
姓名:張三 工資:2140.0
姓名:李四 工資:3210.0
姓名:王五 工資:4280.0
JAVA計(jì)算工人工資,參考例子如下:
import java.util.Scanner;
public class Demo00 {
//定義一個三維數(shù)組,用于記錄每個部門、分支、績效工資
private static final float[][][] SALARY_OF_PER_HOUR = {
{{10.75f,12.50f,14.50f},{11.75f,14.50f,17.50f}},
{{13.00f,16.00f,18.50f},{15.00f,18.50f,22.00f}},
{{16.75f,18.50f,20.50f},{19.25f,25.00f,30.00f}}
};
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//輸入姓名
System.out.println("請輸入姓名:");
String name = sc.nextLine();
//輸入部門并驗(yàn)證
System.out.println("請輸入部門: A,B,C");
char dept = sc.nextLine().charAt(0);
if(dept'A'||dept'C')
{
System.out.println("輸入有誤,系統(tǒng)將退出");
System.exit(0);
}
//輸入分支機(jī)構(gòu)并驗(yàn)證
System.out.println("請輸入分支機(jī)構(gòu): 1,2");
char div = sc.nextLine().charAt(0);
if(div'1'||div'2')
{
System.out.println("輸入有誤,系統(tǒng)將退出");
System.exit(0);
}
//輸入薪績表并驗(yàn)證
System.out.println("請輸入薪績表: a,b,c");
char sal = sc.nextLine().charAt(0);
if(sal'a'||sal'c')
{
System.out.println("輸入有誤,系統(tǒng)將退出");
System.exit(0);
}
//輸入小時(shí)數(shù)
System.out.println("請輸入本周工作時(shí)間(整小時(shí)數(shù)):");
int hours = sc.nextInt();
float salary = 0;
//每個小時(shí)的薪水
float salaryPerHour = SALARY_OF_PER_HOUR[dept-'A'][div-'1'][sal-'a'];
//分別計(jì)算40小時(shí)內(nèi)和超過40小時(shí)的薪水
if(hours=40)
{
salary += salaryPerHour*hours;
}
else
{
salary += salaryPerHour*hours+(hours-40)*1.5*salaryPerHour;
}
//輸出結(jié)果
System.out.println("姓名:\t"+name+"\n部門:\t"+dept+"\n分支機(jī)構(gòu):\t"+div
+"\n薪績表:\t"+sal+"\n工作時(shí)間:\t"+hours+"\n薪水:\t"+salary);
}
}
//Best wishes!
新聞名稱:Java提薪代碼 java漲薪
當(dāng)前鏈接:http://www.rwnh.cn/article32/ddcpjpc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)公司、定制網(wǎng)站、商城網(wǎng)站、網(wǎng)站導(dǎo)航、標(biāo)簽優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)