『壹』 Java简易贷款计算机
你也不说计算公式,不知道怎么计算,我去网上找了一个月支付款的计算公式,不知道和你题目的要求是否一样,如果不一样你就改下公式就行。 java代码如下: public class Loan { public static void main(String[] args){ double rate ;//利率 int year ; //年数 double money ; //贷款总额 double monthpay ;//月付款 Scanner sc = new Scanner(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编写计算器代码
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Calculator extends JFrame
{
private Container container;
private GridBagLayout layout;
private GridBagConstraints constraints;
private JTextField displayField;//计算结果显示区
private String lastCommand;//保存+,-,*,/,=命令
private double result;//保存计算结果
private boolean start;//判断是否为数字的开始
public Calculator()
{
super("Calculator");
container=getContentPane();
layout=new GridBagLayout();
container.setLayout(layout);
constraints=new GridBagConstraints();
start=true;
result=0;
lastCommand = "=";
displayField=new JTextField(20);
displayField.setHorizontalAlignment(JTextField.RIGHT);
constraints.gridx=0;
constraints.gridy=0;
constraints.gridwidth=4;
constraints.gridheight=1;
constraints.fill=GridBagConstraints.BOTH;
constraints.weightx=100;
constraints.weighty=100;
layout.setConstraints(displayField,constraints);
container.add(displayField);
ActionListener insert = new InsertAction();
ActionListener command = new CommandAction();
addButton("Backspace",0,1,2,1,insert);
addButton("CE",2,1,1,1,insert);
addButton("C",3,1,1,1,insert);
addButton("7",0,2,1,1,insert);
addButton("8",1,2,1,1,insert);
addButton("9",2,2,1,1,insert);
addButton("/",3,2,1,1,command);
addButton("4",0,3,1,1,insert);
addButton("5",1,3,1,1,insert);
addButton("6",2,3,1,1,insert);
addButton("*",3,3,1,1,command);
addButton("1",0,4,1,1,insert);
addButton("2",1,4,1,1,insert);
addButton("3",2,4,1,1,insert);
addButton("-",3,4,1,1,command);
addButton("0",0,5,1,1,insert);
addButton("+/-",1,5,1,1,insert);//只显示"-"号,"+"没有实用价值
addButton(".",2,5,1,1,insert);
addButton("+",3,5,1,1,command);
addButton("=",0,6,4,1,command);
setSize(300,300);
setVisible(true);
}
private void addButton(String label,int row,int column,int with,int height,ActionListener listener)
{
JButton button=new JButton(label);
constraints.gridx=row;
constraints.gridy=column;
constraints.gridwidth=with;
constraints.gridheight=height;
constraints.fill=GridBagConstraints.BOTH;
button.addActionListener(listener);
layout.setConstraints(button,constraints);
container.add(button);
}
private class InsertAction implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
String input=event.getActionCommand();
if (start)
{
displayField.setText("");
start=false;
if(input.equals("+/-"))
displayField.setText(displayField.getText()+"-");
}
if(!input.equals("+/-"))
{
if(input.equals("Backspace"))
{
String str=displayField.getText();
if(str.length()>0)
displayField.setText(str.substring(0,str.length()-1));
}
else if(input.equals("CE")||input.equals("C"))
{
displayField.setText("0");
start=true;
}
else
displayField.setText(displayField.getText()+input);
}
}
}
private class CommandAction implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
String command=evt.getActionCommand();
if(start)
{
lastCommand=command;
}
else
{
calculate(Double.parseDouble(displayField.getText()));
lastCommand=command;
start=true;
}
}
}
public void calculate(double x)
{
if (lastCommand.equals("+")) result+= x;
else if (lastCommand.equals("-")) result-=x;
else if (lastCommand.equals("*")) result*=x;
else if (lastCommand.equals("/")) result/=x;
else if (lastCommand.equals("=")) result=x;
displayField.setText(""+ result);
}
public static void main(String []args)
{
Calculator calculator=new Calculator();
calculator.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
『叁』 跪求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 个人贷款还款计算器 的源代码,
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代码如下:
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编写用户输入利率、年数、贷款总额,程序计算每月分期付款金额和总金额。每月分期付款计算公式:
#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源程序
打了个电话给农行的客服(收费的),终于知道公式了。.好麻烦的公式...浪费了我15分钟的电话费。 还有在写公式的过程中遇到了计算x的y次方..谁知道java里怎么计算啊???我是自己写了个方法。.感觉有点麻烦...
注意的是利率.由于开始写的时候没考虑到小数点.所以这里都是按整数算..比如利率是7.5%就写成750..呵呵。.
不直到她公式给错了还是我没听清楚.好象公式有些不准。.明天我去银行问下。.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class MyFrame extends JFrame{
double a;
double b;
double c;
double d;
int ee;
double f;
double g;
double m;
double n;
double o;
double h;
static double x;
static int y;
double z;
String s1;
String s2;
JFrame jf=new JFrame("Counter");
// JPanel jp1=new JPanel();
JPanel jp2=new JPanel();
JPanel jp3=new JPanel();
JPanel jp4=new JPanel();
JPanel jp5=new JPanel();
JPanel jp6=new JPanel();
JPanel jp7=new JPanel();
JPanel jp8=new JPanel();
JPanel jp10=new JPanel();
JPanel jp11=new JPanel();
JPanel jp12=new JPanel();
JLabel jl1=new JLabel("计算器");
JLabel jl2=new JLabel("房屋单价(元/平):");
JLabel jl3=new JLabel("房屋面积(平方):");
JLabel jl4=new JLabel("首付金额(元):");
JLabel jl5=new JLabel("年利率(万分之):");
JLabel jl6=new JLabel("月还款额(元):");
JLabel jl7=new JLabel("总还款额(元):");
JLabel jl10=new JLabel("还款年限(年):");
JLabel jl11=new JLabel("本金(元):");
JLabel jl12=new JLabel("利息(元):");
JTextField jt1=new JTextField("",10);
JTextField jt2=new JTextField("",10);
JTextField jt3=new JTextField("",10);
JTextField jt4=new JTextField("",10);
JTextField jt5=new JTextField("0",15);
JTextField jt6=new JTextField("0",15);
JTextField jt10=new JTextField("",10);
JTextField jt11=new JTextField("0",15);
JTextField jt12=new JTextField("0",15);
JButton b1=new JButton("计算");
JButton b2=new JButton("清空");
MyFrame(){
jf.setLayout(new GridLayout(10,1));
// jp1.add(jl1);
// jf.add(jp1);
jp2.add(jl2);
jp2.add(jt1);
jf.add(jp2);
jp3.add(jl3);
jp3.add(jt2);
jf.add(jp3);
jp4.add(jl4);
jp4.add(jt3);
jf.add(jp4);
jp5.add(jl5);
jp5.add(jt4);
jf.add(jp5);
jp10.add(jl10);
jp10.add(jt10);
jf.add(jp10);
jp6.add(b1);
jp6.add(b2);
jf.add(jp6);
jp7.add(jl6);
jt5.setEditable(false);
jp7.add(jt5);
jf.add(jp7);
jp8.add(jl7);
jt6.setEditable(false);
jp8.add(jt6);
jf.add(jp8);
jp11.add(jl11);
jp11.add(jt11);
jt11.setEditable(false);
jf.add(jp11);
jp12.add(jl12);
jp12.add(jt12);
jt12.setEditable(false);
jf.add(jp12);
jf.setSize(300,400);
jf.setResizable(false);
jf.setVisible(true);
//窗口监听
jf.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
//键盘监听
jt1.addKeyListener(new MyKeyAdapter());
jt2.addKeyListener(new MyKeyAdapter());
jt3.addKeyListener(new MyKeyAdapter());
jt4.addKeyListener(new MyKeyAdapter());
//按键监听
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
a=Double.parseDouble(jt1.getText());
b=Double.parseDouble(jt2.getText());
c=Double.parseDouble(jt3.getText());
d=Double.parseDouble(jt4.getText());
ee=Integer.parseInt(jt10.getText());
// 具体的计算方法
m=1+(d/120000);
n=MyFrame.nPower(m,ee*12);
o=MyFrame.nPower(m,(ee*12-1));
f=((a*b-c)*d/120000*n)/o;
g=f*ee*12;
h=a*b-c;
jt5.setText(Double.toString(f));
jt6.setText(Double.toString(g));
jt11.setText(Double.toString(h));
jt12.setText(Double.toString((g-h)));
}
});
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
jt1.setText("");
jt2.setText("");
jt3.setText("");
jt4.setText("");
jt10.setText("");
jt5.setText("0");
jt6.setText("0");
jt11.setText("0");
jt12.setText("0");
}
});
}
class MyKeyAdapter extends KeyAdapter{
public void keyTyped(KeyEvent e){
char ch=e.getKeyChar();
if(ch<'0'||ch>'9'){e.consume();}
}
}
static double nPower(double _x,int _y){
x=_x;
y=_y;
double z=x;
for(int i=1;i<y;i++){
x=x*z;
}
return x;
}
}
public class Counter{
public static void main(String args[]){
MyFrame m=new MyFrame();
}
}
『捌』 求计算 “贷款支付额”的 java 程序
//文件名为ComputeLoan.java
/**
* Filename is ComputeLoan.java
* Compute the total amount of loan payment
*/
import javax.swing.JOptionPane;
public class ComputeLoan {
//Main Method
public static void main(String [] agrs) {
//enter yearly interst rate
String anunalInterestRateString = JOptionPane.showInputDialog("Please input " +
"the aunual interset\n rate,for example 7.8");
//convert string to double
double annualInterestRate = Double.parseDouble(anunalInterestRateString);
//covert annual interest rate to monthly interest rate
double monthlyInterestRate = annualInterestRate / 1200;
System.out.println("the annual interest rate is "+annualInterestRate);
System.out.println("the monthly interest rate is "+monthlyInterestRate);
//enter number of years
String numOfYearsString = JOptionPane.showInputDialog("Please input " +
"the number of years,for example 5");
//conver string to integer
int numOfYears = Integer.parseInt(numOfYearsString);
System.out.println("the number of years is " + numOfYears);
//enter total loan
String totalLoanInput = JOptionPane.showInputDialog("Please input total loan" +
" ,for example 9899888.2");
//conter string to double
double totalLoan = Double.parseDouble(totalLoanInput);
System.out.println("the total loan is " + totalLoan);
//calculate the total amount of monthly payment
double totalMonthlyPayment = totalLoan * monthlyInterestRate /
(1 - 1 / (Math.pow(1 + monthlyInterestRate, numOfYears * 12)));
double totalYearlyPayment = totalMonthlyPayment * 12 * numOfYears;
//format to keep two digits after the decimal point
totalMonthlyPayment = (int)(totalMonthlyPayment *100) / 100.0;
totalYearlyPayment = (int)(totalYearlyPayment * 100) / 100.0;
//Display result
String output = "The monthly payment is \n"
+ totalMonthlyPayment + "\nThe total loan payment is \n"
+ totalYearlyPayment;
JOptionPane.showMessageDialog(null, output);
}
}
『玖』 用JAVA编程一个房贷计算器
打了个电话给农行的客服(收费的),终于知道公式了。.好麻烦的公式...浪费了我15分钟的电话费。 还有在写公式的过程中遇到了计算x的y次方..谁知道java里怎么计算啊???我是自己写了个方法。.感觉有点麻烦... 注意的是利率.由于开始写的时候没考虑到小数点.所以这里都是按整数算..比如利率是7.5%就写成750..呵呵。. 不直到她公式给错了还是我没听清楚.好象公式有些不准。.明天我去银行问下。. import javax.swing.*; import java.awt.*; import java.awt.event.*; class MyFrame extends JFrame{ double a; double b; double c; double d; int ee; double f; double g; double m; double n; double o; double h; static double x; static int y; double z; String s1; String s2; JFrame jf=new JFrame("Counter"); // JPanel jp1=new JPanel(); JPanel jp2=new JPanel(); JPanel jp3=new JPanel(); JPanel jp4=new JPanel(); JPanel jp5=new JPanel(); JPanel jp6=new JPanel(); JPanel jp7=new JPanel(); JPanel jp8=new JPanel(); JPanel jp10=new JPanel(); JPanel jp11=new JPanel(); JPanel jp12=new JPanel(); JLabel jl1=new JLabel("计算器"); JLabel jl2=new JLabel("房屋单价(元/平):"); JLabel jl3=new JLabel("房屋面积(平方):"); JLabel jl4=new JLabel("首付金额(元):"); JLabel jl5=new JLabel("年利率(万分之):"); JLabel jl6=new JLabel("月还款额(元):"); JLabel jl7=new JLabel("总还款额(元):"); JLabel jl10=new JLabel("还款年限(年):"); JLabel jl11=new JLabel("本金(元):"); JLabel jl12=new JLabel("利息(元):"); JTextField jt1=new JTextField("",10); JTextField jt2=new JTextField("",10); JTextField jt3=new JTextField("",10); JTextField jt4=new JTextField("",10); JTextField jt5=new JTextField("0",15); JTextField jt6=new JTextField("0",15); JTextField jt10=new JTextField("",10); JTextField jt11=new JTextField("0",15); JTextField jt12=new JTextField("0",15); JButton b1=new JButton("计算"); JButton b2=new JButton("清空"); MyFrame(){ jf.setLayout(new GridLayout(10,1)); // jp1.add(jl1); // jf.add(jp1); jp2.add(jl2); jp2.add(jt1); jf.add(jp2); jp3.add(jl3); jp3.add(jt2); jf.add(jp3);
『拾』 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);
}
}