急急急!求java大神帮忙编写一个程序,谢谢啦

Design a class named Account that contains:
■ A private int data field named id for the account (default 0).
■ A private double data field named balance for the account (default 0).
■ A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate.
■ A private Date data field named dateCreated that stores the date when the account was created.
■ A no-arg constructor that creates a default account.
■ A constructor that creates an account with the specified id and initial balance.
■ The accessor and mutator methods for id, balance, and annualInterestRate.
■ The accessor method for dateCreated.
■ A method named getMonthlyInterestRate() that returns the monthly interest rate.
■ A method named withdraw that withdraws a specified amount from the account.
■ A method named deposit that deposits a specified amount to the account.
Write a test program that creates an Account object with an account ID of 1122, a balance of $20,000, and an annual interest rate of 4.5%. Use the withdraw method to withdraw $2,500, use the deposit method to deposit $3,000, and print the balance, the monthly interest, and the date when this account was created.

第1个回答  推荐于2017-10-24
Class Account{
private int id;
private double balance;
private double annuallnterestRate;
private Date dateCreated;

public Account(){
this.id = 0;
this.balance = 0;
this.annuallnterestRate = 0;
this.dateCreated = new Date();
}

public Account(int id, double balance){
this.id = id;
this.balance = balance;
this.dateCreated = new Date();
}

public int getId(){
return this.id;
}

public void setId(int id){
this.id = id;
}

public double getBalance(){
return this.balance
}

public void setBalance(double balance){
this.balance = balance;
}

public double getAnnuallnterestRate(){
return this.annuallnterestRate
}

public void setAnnuallnterestRate(double annuallnterestRate){
this.annuallnterestRate = annuallnterestRate
}

public Date getDateCreated(){
return this.dateCreated;
}

public double getMonthlyInterestRate(){
double monthlyInterest = java.lang.StrictMath.pow(this.annuallnterestRate,1.0/12)-1;
return monthlyInterest;
}

public String withdraw(double amount){
this.balance = this.balance-amount;
return "withdraw success";
}

public String deposit(double amount){
this.balance = this.balance+amount;
return "deposit success";
}

public static void main(String[] args){
Account account = new Account(1122,20000.00);
account.setAnnuallnterestRate(0.045);
account.withdraw(2500.00);
account.deposit(3000.00);
System.out.println(account.getBalance());
System.out.println(account.getMonthlyInterestRate());
System.out.println(account.getDateCreated());
}

}
不谢!分数拿来~本回答被提问者采纳
第2个回答  2017-10-24
你这个编程的难度不是一般的高啊,还是全英文的题目,感觉有点发酥
第3个回答  2012-11-06
Account.java 类
import java.util.Date;
public class Account {
int id;
double balance;
double annualInterestRate;
private Date dateCreated;
public Account(){
Date date=new Date();
dateCreated=date;
}
public Account(int id,double balance){
Date date=new Date();
dateCreated=date;
this.id=id;
this.balance=balance;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public double getAnnualInterestRate() {
return annualInterestRate;
}
public void setAnnualInterestRate(double annualInterestRate) {
this.annualInterestRate = annualInterestRate;
}
public Date getDateCreated() {
return dateCreated;
}
public double getMonthlyInterestRate(){
return annualInterestRate*balance;
}
public void withdraw(double money){
balance-=money;
}
public void deposit (double money){
balance+=money;
}
}
main.java 主程序
import java.util.Date;
public class main {
public static void main(String[] args) {
Account person=new Account(1122,20000d);
person.setAnnualInterestRate(0.045);
person.withdraw(2500d);
person.deposit(3000d);
System.out.println("the balance is "+person.getBalance()+"$");
System.out.println("the monthly interest is "+person.getMonthlyInterestRate()+"$");
System.out.println("the date when this account was created is "+person.getDateCreated().toLocaleString());;
}
}
运行结果:
the balance is 20500.0$
the monthly interest is 922.5$
the date when this account was created is 2012-11-6 16:54:23
第4个回答  2012-11-06
so easy!

JAVA小程序编写,求大神救急
\/\/IO_001.javaimport java.io.*;public class IO_001{ public staic void main(String[] args)throws IOException{ BufferedWriter bw = new BufferedWriter(new FileWriter("file.txt",true)); bw.write("文件已被创建成功!"); bw.newLine(); bw.write("又添加了一行文字"); ...

用Java编程序!十万火急!谢了
param args \/ public static void main(String[] args) { for(int i=1;i<=9;i++){ \/\/ for(int j=1;j<=i;j++){ System.out.print(j+"*"+j+"="+i*j);System.out.print(" ");if(j==i){ System.out.print("\\n");} } } } } ...

急急急!JAVA编程题,哪位大神可以帮助一下我,十分感谢
public class ThreadA extends Thread {@Overridepublic void run() {System.out.println("I am XXX");}} ThreadB.java:public class ThreadB extends Thread {@Overridepublic void run() {System.out.println("I love XXX");}} Main.java:public class Main {public static void main(String...

急急急 求大神 Java编程 ,从键盘输入十个同学的3门功课的成绩,并输出...
intScores[i] = strs[i][3];System.out.println("第"+(i+1)+"个同学的成绩(最后一个数为总数):"+Arrays.toString( strs[i] ));} Arrays.sort(intScores); \/\/从低到高排序 StringBuffer sb = new StringBuffer();for(int i=intScores.length-1;i>=0;i--){ sb.append( int...

急!!!用Java编写以下程序:
然后将这些语句组合成一个Java应用程序,计算并打印整数从1到10的累加和。要求程序中使用自增语句,用while结构循环执行计算。循环应该在变量x的值为11时终止。public class Du { public static void main(String[] args) { int sum;int x;sum = 0;x = 1;while (x < 11) { sum = sum + ...

求一个简单的JAVA程序,急!!!
private double[] 职称等级={0.8,0.9,1.0,1.1,1.2,1.3,1.4};public int get职称() { return 职称;} public void set职称(int 职称) { this.职称 = 职称;} public Teacher(String ns, String ps) { super(ns, ps);} public double counting() { return this.get课时()*职称...

帮忙用java基础语言编写一个程序 要求如下
import java.util.List;public class QuestionOne { \/ 打开一个文本文件,每次读取一行内容。将每行作为一个String读入,并将那个String对象置入一个Linkedlist中。按相反的顺序打印出Linkedlist中所有的行。同样也打开一个文本文件,以便将文本写入其中。将Linkedlist中的各行随同行号一起写入文件。 很急 请...

用java编一个程序,要求如下,希望哪位大虾帮帮忙,很急!!!
import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.ButtonGroup;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JRadioButton;import javax.swing....

Java 代码 求大神帮助十万火急!!
public static void main(String[] args) {Scanner input = new Scanner(System.in);ArrayList<Integer> L = new ArrayList<>(10);int X = 1;int Y = 0;while (true) {if(L.size()>=10)break;System.out.printf("Integer " + X + ":", (X + 1));X++;Y++;L.add(input.next...

急!求教Java高手!以下是我的Java代码,我在注释中写明了我的想法,和问题...
import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.io.*;class jfr extends JFrame { String getpath;String gettype;String getname;JTextField jf1 = new JTextField();\/\/ 接收用户输入的文件夹路径 JTextField jf2 = new JTextField();\/\/ 接收用户输入的文件夹下...

相似回答