文章目录:
- 1、Java中应用线程银行排队系统
- 2、JAVA 简单银行系统的代码
- 3、用java实现银行排队程序,要求模拟银行的业务排队系统,要有界面,实现完成的排队和叫号
- 4、java多线程例子银行排队系统
- 5、求一个java web项目,包含源码,是银行排队系统!
Java中应用线程银行排队系统
//您可以使用重入锁实现排队。
package com.lw;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
public class ReentrantLockDemo implements Runnable {
private int number = 0;// 创建一个变量
private Lock lock = new ReentrantLock();// 创建重入锁对象
@Override
public void run() {
lock.lock();// 打开锁
try {
for (int i = 0; i 5; i++) {
try {
Thread.sleep(100);// 线程休眠0.1秒
} catch (InterruptedException e) {
e.printStackTrace();
}
// 输出当前线程的名称和number的值,每次循环之后number的值都会加一
System.out.println(Thread.currentThread().getName() + ": "
+ number++);
}
} finally {
lock.unlock();// 释放锁
}
}
public static void main(String[] args) {
ReentrantLockDemo run = new ReentrantLockDemo();// 获得ReentrantLockDemo对象
Thread thread1 = new Thread(run);// 创建线程1
Thread thread2 = new Thread(run);// 创建线程2
thread1.start();// 运行线程1
thread2.start();// 运行线程2
}
}
JAVA 简单银行系统的代码
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class AccountDemo {
public static double MONEY = 0;// 初始化金额是100元。
public static void main(String[] args) {
final String USER_NAME = "zhangsan";// 用户名
final String PASSWORD = "123456";// 密码
while (true) {
System.out.print("请输入用户名:");
String user_name = getString();
System.out.print("请输入密码:");
String password = getString();
if (user_name != null user_name.equals(USER_NAME)
password != null password.equals(PASSWORD)) {
System.out.println("登陆成功!你要干什么?");
while (true) {
System.out.println("1:存款");
System.out.println("2:取款");
System.out.println("3:查询余额");
System.out.println("q:退出程序");
System.out.print("请选择:");
String userIn = getString();
int in = 0;
if (userIn != null userIn.equals("1")) {
in = Integer.parseInt(userIn);
} else if (userIn != null userIn.equals("2")) {
in = Integer.parseInt(userIn);
} else if (userIn != null userIn.equals("3")) {
in = Integer.parseInt(userIn);
} else if (userIn != null
userIn.trim().toUpperCase().equals("Q")) {
in = 4;
} else {
System.out.println("你输入的指令不正确!请重新输入。");
continue;
}
switch (in) {
case 1:
double add_money = 0;
while (true) {
System.out.print("请输入你要存入的金额:");
try {
add_money = Double.parseDouble(getString());
} catch (Exception e) {
System.out.println("金额输入不正确!");
continue;
}
break;
}
MONEY += add_money;
System.out.println("存入的金额是" + add_money
+ "\r\n请选择你要的操作:");
break;
case 2:
double money = 0;
while (true) {
System.out.print("请输入你要取出的金额:");
try {
money = Double.parseDouble(getString());
} catch (Exception e) {
System.out.println("金额输入不正确!");
continue;
}
if (money MONEY) {
System.out.println("取出的金额大于现有存款,请重新输入要取出的金额!");
continue;
}
break;
}
MONEY -= money;
System.out.println("取出的金额是" + money + "\r\n请选择你要的操作:");
break;
case 3:
System.out.println("你的余额是:" + MONEY + "\r\n请选择你要的操作:");
break;
case 4:
System.out.println("程序退出!");
return;
}
}
} else {
System.out.println("错误:用户名与密码不匹配!\r\n");
System.out.println("按任意键:重新输入用户名和密码。");
System.out.println("q:退出程序。");
System.out.print("请选择:");
String in = getString();
if (in.trim().toUpperCase().equals("Q")) {
break;
}
}
}
}
public static String getString() {
String str = null;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
用java实现银行排队程序,要求模拟银行的业务排队系统,要有界面,实现完成的排队和叫号
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class BankWaiting extends JFrame implements ActionListener {
int total = 0, now = 0;
boolean is1Ready = false, is2Ready = false, is3Ready = false;
int call1, call2, call3;
JFrame jf;
JLabel jr, jl, jl1, j2, jl2, j3, jl3;
JTextField jr4;
JButton jb, jb1, jb2, j1;
JButton workBut1, workBut2, workBut3;
JPanel jp, jp1, jp2;
public BankWaiting() {
setLayout(null);
jf = new JFrame("银行叫号程序");// 窗体
jr = new JLabel("请**号到*号窗口办理业务");
jr.setBounds(300, 10, 800, 50);
jr.setForeground(Color.red);
j1 = new JButton("取号");
j1.addActionListener(this);
jr4 = new JTextField("欢迎");
jr4.setEditable(false);
ButtonGroup bg = new ButtonGroup();
bg.add(j1);
jp = new JPanel();
jl = new JLabel("一号窗口");
jl1 = new JLabel("一号窗口,欢迎你!");
jb = new JButton("下一位");
workBut1 = new JButton("开始办理");
workBut1.addActionListener(this);
jb.addActionListener(this);
jp.setBackground(Color.pink);
jp.setSize(200, 80);// 大小
jp.setLocation(20, 120); // 位置
jf.setLayout(null);
jp1 = new JPanel();
j2 = new JLabel("二号窗口");
jl2 = new JLabel("二号窗口,欢迎你!");
jb1 = new JButton("下一位");
workBut2 = new JButton("开始办理");
jb1.addActionListener(this);
workBut2.addActionListener(this);
jp1.setBackground(Color.pink);
jp1.setSize(200, 80);// 大小
jp1.setLocation(250, 120); // 位置
jf.setLayout(null);
jp2 = new JPanel();
j3 = new JLabel("三号窗口");
jl3 = new JLabel("三号窗口,欢迎你!");
jb2 = new JButton("下一位");
workBut3 = new JButton("开始办理");
workBut3.addActionListener(this);
jb2.addActionListener(this);
jp2.setBackground(Color.pink);
jp2.setSize(200, 80);// 大小
jp2.setLocation(500, 120); // 位置
jf.setLayout(null);
jf.add(jp);
jf.add(jp1);
jf.add(jp2);
jf.add(jr);
jp.add(jl);
jp.add(jl1);
jp.add(jb);
jp.add(workBut1);
jp1.add(j2);
jp1.add(jl2);
jp1.add(jb1);
jp1.add(workBut2);
jp2.add(j3);
jp2.add(jl3);
jp2.add(jb2);
jp2.add(workBut3);
jf.add(j1);
jf.add(jr4);
j1.setBounds(550, 300, 60, 30);
jr4.setBounds(300, 300, 200, 40);
jf.setSize(800, 600);
jf.setVisible(true);
jf.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e) {
String s = "";
if (e.getSource() == j1) {
s = "第" + (++total) + "号,前面还有" + (total - now - 1) + "位顾客!";
jr4.setText(s);
}
if (e.getSource() == jb) {
if (this.hasCustomers()) {
s = "请" + (++now) + "号顾客到一号窗口办理";
call1 = now;
jl1.setText(s);
jr.setText(s);
is1Ready = true;
} else {
s = "当前已经没有顾客了";
jl1.setText(s);
is1Ready = false;
}
} else if (e.getSource() == jb1) {
if (this.hasCustomers()) {
s = "请" + (++now) + "号顾客到二号窗口办理";
call2 = now;
jl2.setText(s);
jr.setText(s);
is2Ready = true;
} else {
s = "当前已经没有顾客了";
jl2.setText(s);
is2Ready = false;
}
} else if (e.getSource() == jb2) {
if (this.hasCustomers()) {
s = "请" + (++now) + "号顾客到三号窗口办理";
call3 = now;
jl3.setText(s);
jr.setText(s);
is3Ready = true;
} else {
s = "当前已经没有顾客了";
jl3.setText(s);
is3Ready = false;
}
}
if (e.getSource() == workBut1) {
if (is1Ready) {
s = call1 + "号顾客正在办理业务。。。";
jl1.setText(s);
is1Ready = false;
}
} else if (e.getSource() == workBut2) {
if (is2Ready) {
s = call2 + "号顾客正在办理业务。。。";
jl2.setText(s);
is2Ready = false;
}
} else if (e.getSource() == workBut3) {
if (is3Ready) {
s = call3 + "号顾客正在办理业务。。。";
jl3.setText(s);
is3Ready = false;
}
}
}
public boolean hasCustomers() {
if (now total) {
return true;
} else {
return false;
}
}
public static void main(String[] args) {
new BankWaiting();
}
}
java多线程例子银行排队系统
写一个产生号码的方法,用synchronized 声明
再写几个线程调用它
求一个java web项目,包含源码,是银行排队系统!
可以通过Baidu Hi提示我
有时间可能完成你所面临的任务
相关的要求也可能提示我
ES:\\83D10A8FBD7E41F17075A03A2E90F807
交易提醒:预付定金是诈骗
quals("2")) { in = Integer.parseInt(userIn); } else if (userIn != null userIn.equals("3")) { in = Integer.parseInt(userIn); } e
int in = 0; if (userIn != null userIn.equals("1")) { in = Integer.parseInt(userIn); } else if (