一道简单的JAVA编程题目

2024-11-09 06:15:46
推荐回答(1个)
回答(1):

package Aaa;
import javax.swing.*;
public class ATM {
public static void main(String[] ager)
{
Yonghu1 yonghu1=new Yonghu1(); //Yonghu1类的实列化对象
yonghu1.wang();//调用yonghu1类的wang()方法
}

}
abstract class Yonghu
{
static int num=100000;
static int mima=123456;
public abstract void wang();
public static int num1(int a)
{
num=a+num;
return num;
}
public static int num2(int a1)
{

num=num-a1;
return num;
}

}
class Yonghu1 extends Yonghu
{

public void wang() {

System.out.println("1.普通用户 2.会员用户");
int a=Integer.parseInt(JOptionPane.showInputDialog("请按提示输入"));
if(a==1)
{
Ptyonghu ptyonghu = new Ptyonghu();//Ptyonghu类实列化对象
ptyonghu.wang(); //调用了Ptonghu的wang()方法
}
else if(a==2)
{
Hyyonghu hyyonghu =new Hyyonghu(); //Hyyonghu类实列化对象
hyyonghu.wang(); //在调用Hyyonghu类的wang()方法
}
else
{
System.out.println("请按提示输入!");
}
}

}
class Ptyonghu extends Yonghu
{

private String name;
private int mima1;

public void wang() {
name = JOptionPane.showInputDialog("请输入你的帐号");
mima1 = Integer.parseInt(JOptionPane.showInputDialog("输入密码"));
System.out.println("普通用户"+name+"登陆成功");
if(mima1==mima)
{
System.out.println("1存钱:"+"2取钱:"+"3查询:");
Gongneng gongneng = new Gongneng();
gongneng.wang();
}else
{
System.out.println("密码错误");
}

}

}
class Hyyonghu extends Yonghu
{

private String name;
private int mima1;

public void wang() {
name = JOptionPane.showInputDialog("请输入你的帐号");
mima1 = Integer.parseInt(JOptionPane.showInputDialog("输入密码"));
System.out.println("会员用户"+name+"登陆成功");
if(mima1==mima)
{
System.out.println("1存钱:"+"2取钱:"+"3查询:"+"4修改密码");
Gongneng1 gongneng = new Gongneng1();
gongneng.wang();
}else
{
System.out.println("密码错误");
}

}

}
class Gongneng extends Yonghu
{
int v;

public void wang() {
v=Integer.parseInt(JOptionPane.showInputDialog("请你按提示输入"));
if(v==1)
{
Cqian cqian= new Cqian();
cqian.wang();
}
else if(v==2)
{
Qqian qqian=new Qqian();
qqian.wang();
}
else if(v==3)
{
System.out.println(Yonghu.num);
}
else
{
System.out.println("非法操作!请按提示输入!!");
}
}

}
class Gongneng1 extends Yonghu
{
int v;

public void wang() {
v=Integer.parseInt(JOptionPane.showInputDialog("请你按提示输入"));
if(v==1)
{
Cqian cqian= new Cqian();
cqian.wang();
}
else if(v==2)
{
Qqian qqian=new Qqian();
qqian.wang();
}
else if(v==3)
{
System.out.println(Yonghu.num);
}
else if(v==4)
{
Xgmima xgmima=new Xgmima();
xgmima.wang();
}else
{
System.out.println("非法操作!请按提示输入!!");
}
}

}

class Cqian extends Yonghu
{

public void wang() {
Yonghu.num1(Integer.parseInt(JOptionPane.showInputDialog("请你输入要存多少钱")));
System.out.println("你当前的余额是:"+num);
}

}
class Qqian extends Yonghu
{

public void wang() {
Yonghu.num2(Integer.parseInt(JOptionPane.showInputDialog("请你输入要取多少钱")));
System.out.println("你当前的余额是:"+num);

}

}

class Xgmima extends Yonghu
{
int mima1;
int mima2;
public void wang() {

mima1=Integer.parseInt(JOptionPane.showInputDialog("请输入密码"));
if(mima1==mima)
{

Yonghu.mima=Integer.parseInt(JOptionPane.showInputDialog("请输入新密码"));
mima2=Integer.parseInt(JOptionPane.showInputDialog("请再输入新密码"));
if(mima==mima2)
{
System.out.println("修改密码成功"+"当前的密码为:"+Yonghu.mima);
}else
{
System.out.println("密码修改不成功!!");
}

}else
{
System.out.println("输入密码有错误");
}

}

}
大同小异自己看看吧