完成一个桌面系统,模拟ATM系统(登录、存 取款操作、显示余额)等。 系统包含功能: 1、完成用户的注册和用户的登录。 2、至少完成一个模块的增删改查。 3、用户信息和模块信息存储到数组或者集合或者文 件,或者数据库口均可。 必须使用的知识点 使用集合或者数组或者文件或者数据库存储数据, 使用类的封装。 若有GUI图形界面将加分。帮我生成Java代码

时间: 2024-01-24 11:18:15 浏览: 22
抱歉,我是一个自然语言处理模型,无法为您生成完整的代码。但是,我可以提供一些思路和提示: 1. 用户注册和登录可以使用一个User类进行封装,包含用户名和密码等信息。使用集合或者数据库来存储用户信息。 2. 实现存取款操作时,可以定义一个Account类,包含账户余额等信息。在用户登录后,可以根据用户信息查询对应的账户信息,进行存取款操作。 3. 增删改查模块可以定义一个Module类,包含模块名称、描述等信息。使用集合或者数据库来存储模块信息。 4. 图形界面可以使用Java Swing或JavaFX来实现,包括登录界面、主界面和模块管理界面等。 以下是示例代码,仅供参考: User类: ```java public class User { private String username; private String password; public User(String username, String password) { this.username = username; this.password = password; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } } ``` Account类: ```java public class Account { private String username; private int balance; public Account(String username, int balance) { this.username = username; this.balance = balance; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public int getBalance() { return balance; } public void setBalance(int balance) { this.balance = balance; } public void deposit(int amount) { balance += amount; } public void withdraw(int amount) { balance -= amount; } } ``` Module类: ```java public class Module { private String name; private String description; public Module(String name, String description) { this.name = name; this.description = description; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } } ``` 使用集合存储用户信息和模块信息: ```java List<User> userList = new ArrayList<>(); userList.add(new User("alice", "123456")); userList.add(new User("bob", "abcdef")); List<Account> accountList = new ArrayList<>(); accountList.add(new Account("alice", 1000)); accountList.add(new Account("bob", 500)); List<Module> moduleList = new ArrayList<>(); moduleList.add(new Module("module1", "description1")); moduleList.add(new Module("module2", "description2")); ``` 使用Swing实现登录界面和主界面: ```java public class LoginFrame extends JFrame { private JLabel usernameLabel; private JTextField usernameTextField; private JLabel passwordLabel; private JPasswordField passwordField; private JButton loginButton; public LoginFrame() { setTitle("Login"); setSize(300, 200); setLocationRelativeTo(null); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); usernameLabel = new JLabel("Username:"); usernameTextField = new JTextField(20); passwordLabel = new JLabel("Password:"); passwordField = new JPasswordField(20); loginButton = new JButton("Login"); loginButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String username = usernameTextField.getText(); String password = new String(passwordField.getPassword()); if (validateUser(username, password)) { dispose(); new MainFrame(username).setVisible(true); } else { JOptionPane.showMessageDialog(LoginFrame.this, "Invalid username or password", "Error", JOptionPane.ERROR_MESSAGE); } } }); JPanel panel = new JPanel(new GridLayout(3, 2)); panel.add(usernameLabel); panel.add(usernameTextField); panel.add(passwordLabel); panel.add(passwordField); panel.add(loginButton); add(panel); } private boolean validateUser(String username, String password) { for (User user : userList) { if (user.getUsername().equals(username) && user.getPassword().equals(password)) { return true; } } return false; } } public class MainFrame extends JFrame { private JLabel balanceLabel; private JButton depositButton; private JButton withdrawButton; private JButton moduleButton; private String username; public MainFrame(String username) { this.username = username; setTitle("Main"); setSize(300, 200); setLocationRelativeTo(null); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Account account = getAccountByUsername(username); balanceLabel = new JLabel("Balance: " + account.getBalance()); depositButton = new JButton("Deposit"); depositButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String amountString = JOptionPane.showInputDialog(MainFrame.this, "Enter amount:"); if (amountString != null) { int amount = Integer.parseInt(amountString); account.deposit(amount); balanceLabel.setText("Balance: " + account.getBalance()); } } }); withdrawButton = new JButton("Withdraw"); withdrawButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String amountString = JOptionPane.showInputDialog(MainFrame.this, "Enter amount:"); if (amountString != null) { int amount = Integer.parseInt(amountString); if (account.getBalance() >= amount) { account.withdraw(amount); balanceLabel.setText("Balance: " + account.getBalance()); } else { JOptionPane.showMessageDialog(MainFrame.this, "Insufficient balance", "Error", JOptionPane.ERROR_MESSAGE); } } } }); moduleButton = new JButton("Module"); moduleButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new ModuleFrame().setVisible(true); } }); JPanel panel = new JPanel(new GridLayout(4, 1)); panel.add(balanceLabel); panel.add(depositButton); panel.add(withdrawButton); panel.add(moduleButton); add(panel); } private Account getAccountByUsername(String username) { for (Account account : accountList) { if (account.getUsername().equals(username)) { return account; } } return null; } } public class ModuleFrame extends JFrame { private JTable moduleTable; private JButton addButton; private JButton deleteButton; private JButton updateButton; public ModuleFrame() { setTitle("Module"); setSize(300, 200); setLocationRelativeTo(null); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); String[] columnNames = {"Name", "Description"}; Object[][] rowData = new Object[moduleList.size()][2]; for (int i = 0; i < moduleList.size(); i++) { Module module = moduleList.get(i); rowData[i][0] = module.getName(); rowData[i][1] = module.getDescription(); } moduleTable = new JTable(rowData, columnNames); addButton = new JButton("Add"); addButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String name = JOptionPane.showInputDialog(ModuleFrame.this, "Enter name:"); if (name != null) { String description = JOptionPane.showInputDialog(ModuleFrame.this, "Enter description:"); if (description != null) { moduleList.add(new Module(name, description)); ((DefaultTableModel) moduleTable.getModel()).addRow(new Object[]{name, description}); } } } }); deleteButton = new JButton("Delete"); deleteButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int[] selectedRows = moduleTable.getSelectedRows(); if (selectedRows.length > 0) { int confirm = JOptionPane.showConfirmDialog(ModuleFrame.this, "Are you sure to delete?"); if (confirm == JOptionPane.YES_OPTION) { for (int i = selectedRows.length - 1; i >= 0; i--) { moduleList.remove(selectedRows[i]); ((DefaultTableModel) moduleTable.getModel()).removeRow(selectedRows[i]); } } } } }); updateButton = new JButton("Update"); updateButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int selectedRow = moduleTable.getSelectedRow(); if (selectedRow >= 0) { String name = JOptionPane.showInputDialog(ModuleFrame.this, "Enter name:", moduleTable.getValueAt(selectedRow, 0)); if (name != null) { String description = JOptionPane.showInputDialog(ModuleFrame.this, "Enter description:", moduleTable.getValueAt(selectedRow, 1)); if (description != null) { moduleList.set(selectedRow, new Module(name, description)); ((DefaultTableModel) moduleTable.getModel()).setValueAt(name, selectedRow, 0); ((DefaultTableModel) moduleTable.getModel()).setValueAt(description, selectedRow, 1); } } } } }); JPanel buttonPanel = new JPanel(new GridLayout(3, 1)); buttonPanel.add(addButton); buttonPanel.add(deleteButton); buttonPanel.add(updateButton); JPanel panel = new JPanel(new BorderLayout()); panel.add(new JScrollPane(moduleTable), BorderLayout.CENTER); panel.add(buttonPanel, BorderLayout.EAST); add(panel); } } ```

相关推荐

最新推荐

recommend-type

js实现ATM机存取款功能

主要为大家详细介绍了js实现ATM机存取款功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

银行自动取款机ATM系统需求分析

拟开发一个自动取款系统(参考图1-1),它是一个由自动取款机、中央计算机、分行计算机及柜员终端组成的网络系统。ATM和中央计算机由总行投资购买。总行拥有多台ATM,分别设在全市各主要街道上。分行负责提供分行...
recommend-type

用c语言编写ATM取款机模拟系统

用c语言编写ATM取款机模拟系统,利用到了数组,结构体和指针等知识点,是一个关于c语言的综合运用的示例。
recommend-type

银行ATM自动取款机系统的分析与设计

这是一篇关于银行ATM取款机系统的设计分析,包括需求分析和功能描述,最后给出系统的用例图等,希望对大家有所帮助!
recommend-type

JAVA 实现ATM模拟系统

ATM系统: 动作:存款 取款 查询 修改密码 验证密码 属性:name ID PWD money allNum selfNum bankName 设计出继承关系: 父类普通用户:存款 取款 查询 修改密码 验证密码 子类VIP用户:转账 有四位...
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

spring添加xml配置文件

1. 创建一个新的Spring配置文件,例如"applicationContext.xml"。 2. 在文件头部添加XML命名空间和schema定义,如下所示: ``` <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。