求助!java 一道题,帮忙修改一下!
解决时间 2021-04-25 14:13
- 提问者网友:像風在裏
- 2021-04-24 22:58
这个程序包含两个类,第一个类Account,用来定义一个银行账号基本属性和操作,第二个类AccountDemo用来创建Account的对象,并通过这些对象进行模拟存款,取款,查询账号信息等操作
Account类包括姓名(name),账号(caaNum)余额(balance)3个属性,4个方法:Account()构造方法用来对属性进行设置初始值,withdraw()方法用来向指定帐户取款,deposit()方法用来向指定帐户存款。一个显示账号信息的display()方法。
总的来说,其实就是为某个人开个帐户的意思。。。老师说要用到类的继承
在参考别人的帮助下和自己的胡写。。凑出了下面这团东西。。。
期待可以有人指点一下~错误肯定很多。。。
public class Account
{
String name;
int accNum;
double balance;
public Account(String name,int accNum,double balance)
{
name=name;
accNum=accNum;
balance=balance;
}
public boolean withdraw (double money)
{
balance=balance-money;
return true;
}
public boolean desposit(double money)
{
balance=balance+money;
return true;
}
public boolean display()
{
System.out.println("姓名是"+name);
System.out.println("余额是"+balance);
System.out.println("账号是"+accNum);
return true;
}
}
class AccountDemo extends Account{
AccountDemo()
{
super.Account(Tom,1,400);
one.withdraw(100);
one.desposit(200);
one.display();
}
public static void main(String[]args){
Account one=new Account(Tom,1,400);
one.AccountDemo();
}
}
最佳答案
- 五星知识达人网友:洒脱疯子
- 2021-04-24 23:51
public class Account {
String name;
int accNum;
double balance;
public Account(){}
public Account(String name,int accNum,double balance)
{
this.name=name;
this.accNum=accNum;
this.balance=balance;
}
public boolean withdraw (double money)
{
balance=balance-money;
return true;
}
public boolean desposit(double money)
{
balance=balance+money;
return true;
}
public boolean display()
{
System.out.println("姓名是"+name);
System.out.println("余额是"+balance);
System.out.println("账号是"+accNum);
return true;
}
}
public class AccountDemo extends Account{
public AccountDemo(String name, int accNum, double balance){
super(name,accNum,balance);
super.withdraw(100);
desposit(200);
display();
}
public static void main(String[]args){
Account one=new AccountDemo("Tom",1,400);
}
}
全部回答
- 1楼网友:孤独入客枕
- 2021-04-25 00:26
已经改好,编译通过,运行正确:
class Account
{
String name;
int accNum;
double balance;
public Account(String name,int accNum,double balance)
{
this.name=name;
this.accNum=accNum;
this.balance=balance;
}
public boolean withdraw (double money)
{
balance=balance-money;
return true;
}
public boolean desposit(double money)
{
balance=balance+money;
return true;
}
public boolean display()
{
System.out.println("姓名是"+name);
System.out.println("余额是"+balance);
System.out.println("账号是"+accNum);
return true;
}
}
public class AccountDemo extends Account{
AccountDemo(String s, int id, double b)
{
super(s,id,b);
}
void Demo(){
withdraw(100);
desposit(200);
display();
}
public static void main(String[]args){
AccountDemo one=new AccountDemo("Tom",1,400);
one.Demo();
}
}
我要举报
大家都在看
推荐资讯