「java如何计算工资利息」java计算存款利息

博主:adminadmin 2022-11-28 06:54:09 60

本篇文章给大家谈谈java如何计算工资利息,以及java计算存款利息对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

关于java

public class SavingAccount {

public static float interest;

private float balance;

public static double getInterest() {

return interest;

}

public static void setInterest(float interest) {

SavingAccount.interest = interest;

}

public float getBalance() {

return balance;

}

public void setBalance(float balance) {

this.balance = balance;

}

public SavingAccount(float balance) {

this.balance = balance;

}

public float getMonthInterest() {

return this.getYearInterest()/12;

}

public float getYearInterest(){

return interest*this.balance;

}

public void showBalance(){

System.out.println("Your Balance is: "+this.balance);

}

}

//测试类

class Test{

public static void main(String[] args) {

SavingAccount save = new SavingAccount(10000); //初始化

save.setInterest((float) 0.03); //设置利率

save.showBalance(); //打印余额

System.out.println(save.getYearInterest()); //打印年利率

System.out.println(save.getMonthInterest()); //打印月利率

}

}

怎样计算工资包括年工资,周工资,月工资,用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;}

代码四

我也正在思考中

java 计算存款利息

money(1+rate)^year - money

是money * (1+rate)^year - money,和普通的数学顺序一样,先计算级别高的,括号内的1+rate、再乘方year、再乘 money,最后减money。

转成java的计算式,也是按顺序的,乘方的地方就是按JAVA的函数pow的要求,写进参数。

money*Math.pow((1+rate),year)-money;

JAVA计算存款利息

/**

需求:本金1万元人民币,以一年期整存整取的形式储蓄在银行,一年期利率为2.79%,n年后连本带息共计多少钱。

*/

class Calculate

{

public double calcuTotal(double prin,double rate,int n) //参数分别是本金、利率,存放期

{

double inte=0.00;  //利息

double sum=prin; 

for(int i=0;in;i++)

{

inte=inte+prin*rate; //一年期整存整存的利息算法

}

sum+=inte;

return sum;

}

}

class ParamSet

{

public static void main(String[] args)

{

//设置你要的参数

double prin=10000.00;

double rate=0.0279;

int n=10; //存多少年

Calculate c = new Calculate();

double sum=c.calcuTotal(prin,rate,n);

System.out.println("本金:"+prin+" 元 \n存款利率:"+rate+'\n'+n+"年后连本带息共为:"+sum+"元");

}

}

java 编程 计算工人工资,

JAVA计算工人工资,参考例子如下:

import java.util.Scanner;

public class Demo00 {

//定义一个三维数组,用于记录每个部门、分支、绩效工资

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("输入有误,系统将退出");

System.exit(0);

}

//输入分支机构并验证

System.out.println("请输入分支机构: 1,2");

char div = sc.nextLine().charAt(0);

if(div'1'||div'2')

{

System.out.println("输入有误,系统将退出");

System.exit(0);

}

//输入薪绩表并验证

System.out.println("请输入薪绩表: a,b,c");

char sal = sc.nextLine().charAt(0);

if(sal'a'||sal'c')

{

System.out.println("输入有误,系统将退出");

System.exit(0);

}

//输入小时数

System.out.println("请输入本周工作时间(整小时数):");

int hours = sc.nextInt();

float salary = 0;

//每个小时的薪水

float salaryPerHour = SALARY_OF_PER_HOUR[dept-'A'][div-'1'][sal-'a'];

//分别计算40小时内和超过40小时的薪水

if(hours=40)

{

salary += salaryPerHour*hours;

}

else

{

salary += salaryPerHour*hours+(hours-40)*1.5*salaryPerHour;

}

//输出结果

System.out.println("姓名:\t"+name+"\n部门:\t"+dept+"\n分支机构:\t"+div

+"\n薪绩表:\t"+sal+"\n工作时间:\t"+hours+"\n薪水:\t"+salary);

}

}

//Best wishes!

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;

}

}

关于java如何计算工资利息和java计算存款利息的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

The End

发布于:2022-11-28,除非注明,否则均为首码项目网原创文章,转载请注明出处。