设计一个Account类。Java。不知道为啥运行不出来啊啊啊啊啊啊。。。。。。
找不到或无法加载主类 ComputerAvg 我也搞不懂是怎么回事,尝试了好几种方法都没有用诶。
/**
* 设计一个Account类,(课本P306页,9.7)包括:
* 一个名为id的int类型私有数据域(默认值为0)
* 一个名为balance的double类型的私有数据域(默认值为0)
* 一个名为annualInterestRate的double类型私有数据域存储当前利率(默认值为0).假设所有的账户都有相同的利率
* 一个名为deteCreated的Date类型的私有数据域,存储账户的开户日期
* 一个用于创建默认账户的无参构造方法
* 一个用于创建带特定id和初始余额的账户的构造方法
* id、balance和annualInterestRate的访问器和修改器
* dateCreated的访问器
* 一个名为getMonthlyInterestRate()的方法、返回月利率
* 一个名为withDraw的方法,从账户提取特定数额
* 一个名为deposit的方法向账户存储特定数额
* @author 王沐风
*
*/
import java.sql.Date;
import java.util.Scanner;
public class AccountClass {
//名为id的int类型的私有数据域,账户
private int id=0;
//名为balance的double类型的私有数据域,余额
private double balance=0;
//名为annualInterstRate的double类型的私有数据域,利率
private double annualInterestRate=0;
//名为dateCreate的Date类型的私有数据域
private Date dateCreate;
//用于创建默认账户的无参构造方法
public AccountClass(){
}
//用于创建带特定id和初始余额的账户的构造方法
public AccountClass(int id,double balance){
this.id = id;
this.balance=balance;
}
//id、balance和annualInterestRate的访问器和修改器
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 getannualInterstRate(){
return annualInterestRate;
}
public void setannualInterstRate(double annualInterstRate){
this.annualInterestRate=annualInterstRate;
}
//dateCreated的访问器
public Date dateCreate(){
return dateCreate;
}
//一个名为getMonthlyInterestRate()的方法、返回月利率
public double MonthlyInterestRate(){
double Monthly=0;
if(0==annualInterestRate){
System.out.println("Your annualInterestRate have not set:");
}else{
Monthly=annualInterestRate/12;
}
return Monthly;
}
//名为withDraw的方法,从账户提取特定数额
public void withDraw(double Money){
if(Money<=balance){
this.balance=getbalance()-Money;
}else{
System.out.println("Sorry,your balance have not so much balance!");
}
}
//名为deposit的方法向账户存储特定数额
public void deposit(double money){
if(0!=money){
this.balance=getbalance()+money;
}else{
System.out.println("Please enter effective!");
}
}
//测试
public void main(String[] args){
AccountClass myaccount=new AccountClass();//(170321,10000);
myaccount.setid(321);//修改id
int id=getid();//修改id
myaccount.setbalance(10000);
double balance=getbalance();//修改账户余额
System.out.println("The id of myaccount is "+id+" the balance is "+balance);
Date date=myaccount.dateCreate();//访问账户日期
System.out.println("The date of create id is "+date);
setannualInterstRate(0.0045);//修改年利率,返回年利率
double annualInterstRate=myaccount.getannualInterstRate();
System.out.println("The annualInterestRate is "+annualInterstRate);
double Monthly=myaccount.getbalance();//返回月利率
System.out.println("The monthlyannualInterestRate is "+Monthly);
System.out.println("Please enter the money of withDraw :");
Scanner input = new Scanner(System.in);
double money=input.nextDouble();
myaccount.withDraw(money);//取钱
System.out.println("The balance is "+balance);
System.out.println("Please enter the money of deposite :");
Scanner input1 = new Scanner(System.in);
double moneydeposite=input1.nextDouble();
myaccount.deposit(moneydeposite);
System.out.println("The balance is "+balance);
}
}