java编程问题...求速解答.....定义三个银行账号类.每个类都有账号 密码等private属
关注:251 答案:1 mip版
解决时间 2021-02-02 06:17
提问者神经质
2021-02-01 08:49
java编程问题...求速解答.....定义三个银行账号类.每个类都有账号 密码等private属性,每个类都有存取转账三个public方法.分别为银行,工行,交行三个银行。工行、交行类要继承银行类,并实现方法重载。演示不同银行帐号之间转账,用帐号存取款,查询余额等。
最佳答案
二级知识专家蓝莓九栀
2021-02-01 08:55
稍等一会,我帮你写
银行类
public class Bank {
private double count;//余额
private static String account="test";//账户
private static String password="test";//密码
//取款
public void getMoney(String account,String password,double num){
if(login(account,password)){
if(count
System.out.println("银行余额不足!");
}else{
count=count-num;
System.out.println("当前余额: "+count);
}
}else{
System.out.println("账号或密码错误!");
}
}
//存款
public void setMoney(String account,String password,double num){
if(login(account,password)){
count=count+num;
System.out.println("当前余额: "+count);
}else{
System.out.println("账号或密码错误!");
}
}
//查询余额
public void queryMoney(String account,String password){
if(login(account,password)){
System.out.println("当前余额: "+count);
}else{
System.out.println("账号或密码错误!");
}
}
//登录
private static boolean login(String acc,String pwd){
if(account.equals(acc)&&password.equals(pwd)){
return true;
}else{
return false;
}
}
}
工行类
public class ICBC extends Bank {
private double count;//余额
private static String account="test";//账户
private static String password="test";//密码
//取款
public void getMoney(String account,String password,double num){
if(login(account,password)){
if(count
System.out.println("工行余额不足!");
}else{
count=count-num;
System.out.println("工行当前余额: "+count);
}
}else{
System.out.println("工行账号或密码错误!");
}
}
//存款
public void setMoney(String account,String password,double num){
if(login(account,password)){
count=count+num;
System.out.println("工行当前余额: "+count);
}else{
System.out.println("工行账号或密码错误!");
}
}
//查询余额
public void queryMoney(String account,String password){
if(login(account,password)){
System.out.println("工行当前余额: "+count);
}else{
System.out.println("工行账号或密码错误!");
}
}
//登录
private static boolean login(String acc,String pwd){
if(account.equals(acc)&&password.equals(pwd)){
return true;
}else{
return false;
}
}
}
交行类
public class COMM extends Bank {
private double count;//余额
private static String account="test";//账户
private static String password="test";//密码
//取款
public void getMoney(String account,String password,double num){
if(login(account,password)){
if(count
System.out.println("交行余额不足!");
}else{
count=count-num;
System.out.println("交行当前余额: "+count);
}
}else{
System.out.println("交行账号或密码错误!");
}
}
//存款
public void setMoney(String account,String password,double num){
if(login(account,password)){
count=count+num;
System.out.println("交行当前余额: "+count);
}else{
System.out.println("交行账号或密码错误!");
}
}
//查询余额
public void queryMoney(String account,String password){
if(login(account,password)){
System.out.println("交行当前余额: "+count);
}else{
System.out.println("交行账号或密码错误!");
}
}
//登录
private static boolean login(String acc,String pwd){
if(account.equals(acc)&&password.equals(pwd)){
return true;
}else{
return false;
}
}
}
测试类
public class Test {
public static void main(String[] args) {
Bank b=new Bank();
ICBC i=new ICBC();
COMM c=new COMM();
//存款
b.setMoney("test", "test", 100);
i.setMoney("test", "test", 100);
c.setMoney("test", "test", 100);
//取款
b.getMoney("test", "test", 1000);
b.getMoney("test", "test", 10);
i.getMoney("test", "test", 1000);
i.getMoney("test", "test", 10);
c.getMoney("test", "test", 1000);
c.getMoney("test", "test", 10);
//查余额
b.queryMoney("test", "test");
i.queryMoney("test", "test");
c.queryMoney("test", "test");
}
}
我要举报
如以上问答内容为低俗/色情/暴力/不良/侵权的信息,可以点下面链接进行举报,我们会做出相应处理,感谢你的支持!
→点此我要举报以上信息!←
推荐资讯
大家都在看