abstract class Person{
馬村網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián)公司,馬村網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為馬村上1000家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站制作要多少錢,請找那個售后服務(wù)好的馬村做網(wǎng)站的公司定做!
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("張三","領(lǐng)導");
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
());
}
}
看下吧,有什么不足的請指出來
JAVA計算工人工資,參考例子如下:
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();
//輸入部門并驗證
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);
}
//輸入分支機構(gòu)并驗證
System.out.println("請輸入分支機構(gòu): 1,2");
char div = sc.nextLine().charAt(0);
if(div'1'||div'2')
{
System.out.println("輸入有誤,系統(tǒng)將退出");
System.exit(0);
}
//輸入薪績表并驗證
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ù)
System.out.println("請輸入本周工作時間(整小時數(shù)):");
int hours = sc.nextInt();
float salary = 0;
//每個小時的薪水
float salaryPerHour = SALARY_OF_PER_HOUR[dept-'A'][div-'1'][sal-'a'];
//分別計算40小時內(nèi)和超過40小時的薪水
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分支機構(gòu):\t"+div
+"\n薪績表:\t"+sal+"\n工作時間:\t"+hours+"\n薪水:\t"+salary);
}
}
//Best wishes!
class Salary{
private int no;
private String name;
private double deal;
private double tax;
public Salary(int no,String name,double deal,double tax){
this.no=no;
this.name=name;
this.deal=deal;
this.tax=tax;
}
public double count(){
return this.deal-this.tax;
}
public void output(){
System.out.println("工號"+this.no);
System.out.println("姓名"+this.name);
System.out.println("應(yīng)發(fā)工資"+this.deal);
System.out.println("稅金"+this.tax);
System.out.println("實發(fā)工資"+count());
}
public static void main(String[] args){
Salary a=new Salary(1,"張三",1000,200);
a.output();
Salary b=new Salary(2,"李四",1500,200);
b.output();
}
}
一:將員工姓名、工資封裝成一個對象
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;
}
}
二:初始化一個數(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);
}
}
按照題目要求編寫的計算員工稅后工資的Java程序如下
import java.util.Scanner;
public class Tax{
public static double calculateSalary(double s){
double sat=0;
if(s=5000){
sat=s;
}else if(5000s s=6500){
sat=s-(s-5000)*0.03;
}else if(6500s s=9500){
sat=s-(s-5000)*0.1;
}else if(9500s s=14000){
sat=s-(s-5000)*0.2;
}else if(14000s s=40000){
sat=s-(s-5000)*0.25;
}else if(40000s s=60000){
sat=s-(s-5000)*0.3;
}else if(60000s s=85000){
sat=s-(s-5000)*0.35;
}
return sat;
}
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=0;
double s,sat;
double[] salary=new double[10];
double[] salaryAfterTax=new double[10];
System.out.print("是否添加新員工薪水 y/n?");
String add=sc.next();
while(add.equals("y")){
s=sc.nextDouble();
salary[n]=s;
sat=calculateSalary(s);
salaryAfterTax[n]=sat;
n++;
System.out.print("是否添加新員工薪水 y/n?");
add=sc.next();
}
for(int i=0;in-1;i++){
for(int j=0;jn-1-i;j++){
if(salaryAfterTax[j]salaryAfterTax[j+1]){
double temp=salaryAfterTax[j];
salaryAfterTax[j]=salaryAfterTax[j+1];
salaryAfterTax[j+1]=temp;
}
}
}
System.out.printf("稅后工資高的前三名是:%.2f,%.2f,%.2f",salaryAfterTax[0],salaryAfterTax[1],salaryAfterTax[2]);
}
}
代碼一
public double earnings()
{double a=50000.456;
return a;
}
代碼二
public double earnings()
{double b=2000;
return 12*b;}
代碼三
public double earnings()
{double c=500;
return 52*c;}
代碼四
我也正在思考中