『壹』 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);
}
}