
正文
关于薪水的java代码 java编写计算工资
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
java计算工资
person类:
public abstract class Person {
public double pay; // 总工资
public int hour; // 课时
public double countPay(int hour) {
return pay;
}
}
助教类:
public class Assistant extends Person {
public final double BASE_PAY = 800; // 基本工资
public final double HOUR_PAY = 25; // 每课时的费用
public double countPay(int hour) {
pay = BASE_PAY + hour * HOUR_PAY;
return pay;
}
}
讲师类:
public class Instructor extends Person {
public final double BASE_PAY = 1000; // 基本工资
public final double HOUR_PAY = 35; // 每课时的费用
public double countPay(int hour) {
pay = BASE_PAY + hour * HOUR_PAY;
return pay;
}
}
副教授类:
public class AssistantProfesson extends Person {
public final double BASE_PAY = 1200; // 基本工资
public final double HOUR_PAY = 40; // 每课时的费用
public double countPay(int hour) {
pay = BASE_PAY + hour * HOUR_PAY;
return pay;
}
}
教授类:
public class Professor extends Person {
public final double BASE_PAY = 1400; // 基本工资
public final double HOUR_PAY = 50; // 每课时的费用
public double countPay(int hour) {
pay = BASE_PAY + hour * HOUR_PAY;
return pay;
}
}
测试类:
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Test {
public static void main(String[] args) {
System.out.println("人员类型如下:");
System.out.println("1 = 助教\r\n2 = 讲师\r\n3 = 副教授\r\n4 = 教授");
System.out.print("请选择:");
BufferedReader personType = new BufferedReader(new InputStreamReader(
System.in));
String type = null;
int hour = 0;
try {
type = personType.readLine();
} catch (Exception e) {
e.printStackTrace();
}
if (type.matches("[1-4]{1}")) {
switch (Integer.valueOf(type)) {
case 1:
hour = getHour();
if(hour == 0){return;}
Person p1 = new Assistant();
double pay1 = p1.countPay(hour);
System.out.println("助教工作" + hour + "课时的工资为:" + pay1);
break;
case 2:
hour = getHour();
if(hour == 0){return;}
Person p2 = new Instructor();
double pay2 = p2.countPay(hour);
System.out.println("讲师工作" + hour + "课时的工资为:" + pay2);
break;
case 3:
hour = getHour();
if(hour == 0){return;}
Person p3 = new AssistantProfesson();
double pay3 = p3.countPay(hour);
System.out.println("副教授工作" + hour + "课时的工资为:" + pay3);
break;
case 4:
hour = getHour();
if(hour == 0){return;}
Person p4 = new Professor();
double pay4 = p4.countPay(hour);
System.out.println("教授工作" + hour + "课时的工资为:" + pay4);
break;
}
} else {
System.out.println("输入数据错误!程序提前推出!");
return;
}
}
public static int getHour() {
System.out.print("请输入工作时间:");
BufferedReader hours = new BufferedReader(new InputStreamReader(
System.in));
String strHour = null;
int hour = 0;
try {
strHour = hours.readLine();
} catch (Exception e) {
e.printStackTrace();
}
if (strHour.matches("^[0-9]+?")) {
hour = Integer.parseInt(strHour);
} else {
System.out.println("输入参数不正确!程序提前推出!");
}
return hour;
}
}
相关问答
Q1: 用Java编写个人薪水所得
您好关于薪水的java代码:
代码如下关于薪水的java代码,供参考关于薪水的java代码:
主函数,获得输入值,输出税率
递归方法,根据输入返回税率
结果展示
Q2: java算工资的编程题?
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("应发工资"+this.deal);
System.out.println("税金"+this.tax);
System.out.println("实发工资"+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();
}
}
Q3: 用java,编写五个人的工资表,计算出最高工资,平均数
import java.util.Arrays;
class YG implements ComparableYG{//员工类,实现比较接口
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) {//通过这个方法, 实现按工资排序
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
Q4: 怎样计算工资包括年工资,周工资,月工资,用java编写程序
代码一
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;}
代码四
我也正在思考中
Q5: 使用java编写程序实现输入员工工资,获得员工的平均工资,要求使用象数组类型的
一:将员工姓名、工资封装成一个对象
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;
}
}
二:初始化一个数组,算平均工资
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("员工人数:" + staffs.length + " 总工资:" + sum + " 平均工资:" + sum / staffs.length);
}
}
关于关于薪水的java代码和java编写计算工资的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







