作业帮 > 综合 > 作业

关于java编程问题Write an algorithm and a program to settle the fol

来源:学生作业帮 编辑:搜狗做题网作业帮 分类:综合作业 时间:2024/07/02 19:39:26
关于java编程问题
Write an algorithm and a program to settle the following question.A
bank account starts out with an initial balance,iBalance.Interest is
computed monthly at 6% per year (0.5% per month).Every month $500.00
is withdrawn to meet education expenses.After how many years is the
account depleted?
There are some values for which the algorithm
you developed may not terminate.Modify your algorithm to make sure it
always terminates.The program should read the iBalance from command
line.
The input of the program is iBalance
Examples of the output of the program:
6 years and 1 month
1 year and 6 months
8 months (note that the output should not be as 0 years and 8 month)
Note:
Withdraws will be at the end of each month.For example if
the deposit is equal to 500$,then at the end of the first
month the iBalance will be equal to 500*(1+0.06/12) = 502.50
$.
By taking 500$,the iBalance will be equal to
2.5$,and at the end of the second month the iBalance will be
equal to 2.51 $.As the result at the end of the second month
the account will be depleted.
算法流程图我写的是:
(Define terms)
0.1 n=iBalance
0.2 T=month
START
1.T ← 0
2.Input n
3.While (n>0),do
3.1 n*=(1+0.06/12)
3.2 n-=500
3.3 T+=1
4.Print T
END
求java code,同时求大神帮助看看流程图有没有错误,应该怎么改正
关于java编程问题Write an algorithm and a program to settle the fol
package com.pb.test;
public class MyPoint { private double x;
private double y;

public MyPoint(){
this.x = 0;
this.y = 0;
}

public MyPoint(double x,double y){
this.x = x;
this.y = y;
}

public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}

public double distance(MyPoint point1, MyPoint point2) {
return Math.sqrt((point1.x - point2.x) * (point1.x - point2.x)
+ (point1.y - point2.y)*(point1.y - point2.y));
}
}
看看这个,修改了distance方法,通过了测试
以上回答你满意么?