當前位置:首頁 » 利息利率 » 計算銀行貸款利息java代碼
擴展閱讀
中國住房貸款法律 2025-02-11 10:28:30
泛華金融貸款20萬 2025-02-11 10:11:03
貸款的汽車能抵押貸款 2025-02-11 10:08:43

計算銀行貸款利息java代碼

發布時間: 2022-06-12 01:00:08

① 跪求JAVA編寫的銀行利息計算器代碼

這個很簡單,只是我對這些計算規則不熟悉
import java.util.ListIterator;
import java.util.Stack;

public class CalStr {
private String src;

/**
* constructor
*
* @param srcthe string(expression) to calculate
*/
public CalStr(String src) {
this.src = src;
}

/**
* calculate to get the result
*
* @return(double)result
*/
public double getResult() {
String postfix = getPostfix();
Stack stk = new Stack();
// System.out.println(postfix);
String parts[] = postfix.split(" +");
double result = 0;
for (int i = 0; i < parts.length; i++) {
char tmp = parts[i].charAt(0);
if (!isOperator(tmp)) {
stk.push(parts[i]);
} else {
double a = Double.parseDouble((String) stk.pop());
double b = Double.parseDouble((String) stk.pop());
// b is followed by a in the orignal expression
result = calculate(b, a, tmp);
stk.push(String.valueOf(result));
}
}
return result;
}

/**
* test if the character is an operator,such +,-,*,/
*
* @param opthe character to test
* @returntrue if op is an operator otherwise false
*/
private boolean isOperator(char op) {
return (op == '+' || op == '-' || op == '*' || op == '/');
}

/**
* calculate an expression such (a op b)
*
* @param anumber 1
* @param bnumber 2
* @param opthe operator
* @return(double)(a op b)
*/
public double calculate(double a, double b, char op) {
switch (op) {
case '+':
return a + b;
case '-':
return a - b;
case '*':
return a * b;
case '/':
return a / b;
}
return -1;
}

/**
* convert the suffix to postfix
*
* @returnthe postfix as a string
*/
private String getPostfix() {
Stack stk = new Stack();
String postfix = new String();
char op;
int i = 0;
while (i < src.length()) {
if (Character.isDigit(src.charAt(i)) || src.charAt(i) == '.') {
postfix += " ";
do {
postfix += src.charAt(i++);
} while ((i < src.length())
&& (Character.isDigit(src.charAt(i))));
postfix += " ";
}

else {
switch (op = src.charAt(i++)) {
case '(':
stk.push("(");
break;

case ')':
while (stk.peek() != "(") {
String tmp = (String) stk.pop();
postfix += tmp;
if (tmp.length() == 1 && isOperator(tmp.charAt(0)))
postfix += " ";
}
stk.pop();
postfix += " ";
break;

case '+':
case '-':
while ((!stk.empty()) && (stk.peek() != "(")) {
postfix += stk.pop() + " ";
}
stk.push(String.valueOf(new Character(op)));
break;

case '*':
case '/':
while ((!stk.empty())
&& ((stk.peek() == "*") || (stk.peek() == "/"))) {
postfix += stk.pop() + " ";
}
stk.push(String.valueOf(new Character(op)));
break;
}
}
}
ListIterator it = stk.listIterator(stk.size());
while (it.hasPrevious())
postfix += it.previous() + " ";
return postfix.trim().replaceAll(" +\\\\.", ".");
}

/**
* main function
*
* @param args
*/
public static void main(String args[]) {
System.out.println(new CalStr("((1.5+6.000)*9+9.36)*(8+9-8*8+8*7)")
.getResult());
}
}

new CalStr( 寫上你的計算公式 );

② 用java編寫程序:求銀行本息的!題目如下:

簡單些了個,如果沒理解錯的話,應該可以滿足要求:

public class Benxi{

private double benxi;//本息
private double lilu;//年利率

//計算本息
private double resBenxi(double money,int year){
benxi=money+money*getLilu(year)*year;
return benxi;
}

//選擇利率
private double getLilu(int year){
switch(year){
case 1:
lilu=2.25/100;
break;
case 2:
lilu=2.7/100;
break;
case 3:
lilu=3.24/100;
break;
case 5:
lilu=3.6/100;
break;
}
return lilu;
}

public static void main(String[] args){
Benxi bx=new Benxi();
System.out.println("10000元存一年的本息為:"+bx.resBenxi(10000,1));
System.out.println("10000元存兩年的本息為:"+bx.resBenxi(10000,2));
System.out.println("10000元存三年的本息為:"+bx.resBenxi(10000,3));
System.out.println("10000元存五年的本息為:"+bx.resBenxi(10000,5));

}
}

③ 最簡單的銀行管理系統有利息演算法的java簡單代碼

package com.nsu.java.base;

import java.util.Scanner;

public class homework {
public static void main(String[] args) {
double a=0.0115;
double b;
double d;
double c,f;
System.out.println("請輸入您的存款金額:");
Scanner it=new Scanner(System.in);
d=it.nextDouble();
System.out.println("請輸入您的存款期限:");
b=it.nextDouble();
c=d-d+d*a;
f=b*c;

System.out.println("您的預期收入為:"+f);

}
}

建議把上面的包名改一下。

④ 用JAVA編寫用戶輸入利率、年數、貸款總額,程序計算每月分期付款金額和總金額。每月分期付款計算公式:

#include<stdio.h>
#include<conio.h>
main()
{
int Year; /*年數*/
double Rate ,Monrate,Load,Money; /*變數依次為利率,月利率,貸款總額,月還款額*/

printf("Please input money rate\n ");
scanf("%lf",&Rate);
printf("Please input monthly money rate\n ");
scanf("%lf",&Monrate);
printf("Please input load ceiling\n ");
scanf("%lf",&Load);
printf("Please input year\n ");
scanf("%d",&Year);
Money=(Load*Monrate)/(1-(1.0/((1+Monrate)*Year*12)));
printf("------Your monthly payments is %lf------\n",Money);
getch();
}
這是c語言板的,Java還沒學呢, 思想都差不多的。

⑤ java編寫程序:要求用戶輸入貸款的年利率,總金額和年數,程序計算月支付金額和

你也不說計算公式,不知道怎麼計算,我去網上找了一個月支付款的計算公式,不知道和你題目的要求是否一樣,如果不一樣你就改下公式就行。

java代碼如下:

publicclassLoan{
publicstaticvoidmain(String[]args){
doublerate;//利率
intyear;//年數
doublemoney;//貸款總額
doublemonthpay;//月付款

Scannersc=newScanner(System.in);
System.out.println("輸入月利率:");
rate=sc.nextDouble();
System.out.println("輸入年數:");
year=sc.nextInt();
System.out.println("輸入貸款總額:");
money=sc.nextDouble();

//計算月付款
monthpay=(money*rate)/Math.abs(1-(1/(1+rate)*year*12));
System.out.println("每月應該還貸款:"+monthpay);
}
}

⑥ Java課程設計 銀行貸款多種還款方式的計算

貸款期限在一年以內的,可採用到期一次還本付息。// 付息的 利率多少 每月還款額= 等額本金還款=// 貸款利率 // 這個計算利率又是多少// 程序 是出來了 但 你這些都 不太清楚 哦 能發 詳細點 不

⑦ 求一個 java 個人貸款還款計算器 的源代碼,

import javax.swing.JOptionPane;

public class Pay {
public static void main(String args[]){

String loanString = JOptionPane.showInputDialog("請輸入貸款本金( loanAmout):such as 20000.00") ;

double loanAmount= Double.parseDouble(loanString);

String dateString = JOptionPane.showInputDialog("請輸入貸款期(loanDate):between 24-60");

int loanDate = Integer.parseInt(dateString);

String monthRateString = JOptionPane.showInputDialog("請輸入月利率 (MonthRate):such as 0.00005");

double monthRate = Double.parseDouble(monthRateString);

double pay_Per_Month = (loanAmount+loanAmount * loanDate * monthRate)/loanDate;

JOptionPane.showMessageDialog(null, pay_Per_Month);
}
}

⑧ 用Java編寫一個自由還貸計算器。求空白部分。

⑨ 簡單的java程序,希望高手幫我改成我想要的功能……

import java.awt.*;
import java.util.*;
import java.awt.event.*;

import javax.swing.*;
public class LoanJFrame extends JFrame implements ActionListener
{
private JTextField text_money,text_rate,text_year;
private JSpinner spin_year,spin_month;
private JButton button;
private JTable table;
private String titles[]={"年月","本金余額(元)","月還本金(元)","月還利息(元)","月還本息(元)"};
public LoanJFrame()
{
super("銀行貸款按月還本利息的計算");
this.setBounds(300,240,740,400);
this.setBackground(Color.LIGHT_GRAY);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel panel=new JPanel();
this.getContentPane().add(panel,"North");

panel.add(new JLabel("貸款金額"));
text_money=new JTextField("100",6);
panel.add(text_money);

panel.add(new JLabel("元 貸款利率"));
text_rate=new JTextField("0.5025",6);
panel.add(text_rate);

panel.add(new JLabel("%/月 貸款年限"));
text_year=new JTextField("1",3);
panel.add(text_year);

panel.add(new JLabel("年 起始年月"));
Calendar today=Calendar.getInstance();
int year=today.get(Calendar.YEAR);
int nextmonth=today.get(Calendar.MONTH)+1;
nextmonth=nextmonth%12+1;
if(nextmonth==1)
year++;
spin_year=new JSpinner();
spin_year.setValue(year);
panel.add(spin_year);
panel.add(new JLabel("年"));
spin_month=new JSpinner(new SpinnerNumberModel(nextmonth,1,12,1));
panel.add(spin_month);
panel.add(new JLabel("月"));
button=new JButton("計算");
panel.add(button);
button.addActionListener(this);
table=new JTable( getSzFh(),titles);
this.getContentPane().add(new JScrollPane(table));
this.setVisible(true);
}
//監聽
public void actionPerformed(ActionEvent e)
{
table=new JTable(getSzFh(),titles);
this.getContentPane().add(new JScrollPane(table));
this.setVisible(true);
}

//計算 返回一個數組
public Object[][] getSzFh(){
System.out.println(text_year.getText());
int months=Integer.parseInt(text_year.getText())*12;
Object datas[][]=new Object[months][5];
int year=Integer.parseInt(""+spin_year.getValue());
int month=Integer.parseInt(""+spin_month.getValue());
double leavings=Double.parseDouble(""+text_money.getText());
double pay=leavings/months;
double rate=Double.parseDouble(""+text_rate.getText());
for(int i=0;i<months;i++)
{
datas[i][0]=year+"年"+month+"月";
datas[i][1]=String.format("%9.2f",leavings);
datas[i][2]=String.format("%9.2f",pay);
datas[i][3]=String.format("%9.2f",leavings*rate*0.01);
datas[i][4]=String.format("%9.2f",pay+leavings*rate*0.01);
if(month==12)
year++;
month=month%12+1;
leavings-=pay;
}
return datas;
}
public static void main(String arg[])
{
new LoanJFrame();
}

}

⑩ java代碼的問題,一個銀行借貸利率計算的代碼,用的是類和對象。之前的代碼在這里。。。。。。

最後三行你得改成這樣才能測試Money類:
int year=input.nextInt();
double money=A.loan(loan,year);
System.out.println("money="+money);
完整的測試類如下:
import java.util.Scanner;
public class TestMOney {
public static void main(String[]args){
Scanner input=new Scanner(System.in);
Money A=new Money();
System.out.println("輸入借款");
double loan=input.nextDouble();
System.out.println("輸入年限");
int year=input.nextInt();
double money=A.loan(loan,year);
System.out.println("money="+money);
}
}