⑴ java編寫銀行賬戶操作模擬
這個很簡單,你只是要設計對吧?如果你不實現GUI的話,就可以用字元輸入來公職系統,一個main方法,監聽著用戶輸入,1存款、2取款、3查詢余額、4顯示賬號.用戶輸入什麼數字進入到相應的方法。每個方法可以用jdbc直接訪問oracle。
但是,個人建議,做個GUI沒什麼難的,這個BS結構的比較合適。不知道你的jsp+js+css等學的如何,如果可以的話可以用spring+struts+ibitis來做,很簡單,估計1天就弄好了。
有什麼不懂可以追問
望採納
⑵ JAVA編寫銀行賬戶程序摸擬銀行賬戶的存\取款操作
public class ATM {
public static void main(String[] args) {
// 開立帳號
Account account = new Account();
// 在 account 中存 10,000 元
account.setBalance(10000);
// 檢查 account 中的存款
System.out.println("帳戶原始金額 : " + account.getBalance() + " 元");
// 小明, 小華與小英一起對 account 進行提款的動作
WithDraw s1 = new WithDraw("小明", account, 5000); // 小明 在 account 中提 5000 元
WithDraw s2 = new WithDraw("小華", account, 2000); // 小華 在 account 中提 2000 元
WithDraw s3 = new WithDraw("小英", account, 4000); // 小英 在 account 中提 4000 元
s1.start();
s2.start();
s3.start();
}
}
//帳戶
class Account {
private int balance; // 帳戶餘額
public int getBalance() { // 取得帳戶餘額
return balance;
}
public void setBalance(int money) { // 設定帳戶餘額
balance = money;
}
// 提款方法
public void withDraw(Account account, int withdrawMoney) {
String tName = Thread.currentThread().getName(); // tName=提款人
System.out.println(tName + " 開始提款 ... ");
boolean withDrawStatus; // 提款狀態 說明:false=提款失敗, true=提款成功
synchronized(ATM.class) {
int tmpBalabce = account.getBalance(); // 取得最新帳戶餘額
//用 for-loop 模擬提款時系統所花的時間
for(double delay=0;delay<99999999;delay++) {
// ... 提款進行中 ...
}
tmpBalabce = tmpBalabce - withdrawMoney; // 最新帳戶餘額 - 欲提款金額 (用來判斷是否餘額足夠的依據)
if (tmpBalabce < 0) { // 判斷是否餘額足夠
withDrawStatus = false;
System.out.println("....................");
System.out.println(" 帳戶餘額不足!");
System.out.println("....................");
} else {
withDrawStatus = true;
account.setBalance(tmpBalabce); // 回存account最後剩餘金額
}
}
System.out.println(tName + "的交易單:");
System.out.println("\t欲提款金額:" + withdrawMoney + "元");
System.out.println("\t帳戶餘額:" + account.getBalance());
if(withDrawStatus == true){
System.out.println(tName + " 完成提款 ... ");
} else {
System.out.println(tName + " 提款失敗 ... ");
}
System.out.println("-------------------------------");
}
}
// 提款類別
class WithDraw extends Thread {
private Account account; // 帳號
private int withdrawMoney; // 欲提款的金額
// tName:執行緒名稱, account:Account物件名稱, withdrawMoney:欲提款金額
public WithDraw(String tName, Account account, int withdrawMoney) {
setName(tName);
this.account = account;
this.withdrawMoney= withdrawMoney;
}
public void run() {
// 執行提款動作(account:帳號, withdrawMoney 欲提款金額)
account.withDraw(account, withdrawMoney); // 執行提款動作
}
}
⑶ 用JAVA編程設計一個銀行賬戶類,其中包括以下內容,並用字元界面模擬存款和取款過程。
import java.util.Scanner;
public class ZH {
private String zh;//賬戶
private String password;//密碼
private String openTime;//開戶時間
private String sfz;//身份證號
private double je;//存款金額
public String getZh() {
return zh;
}
public void setZh(String zh) {
this.zh = zh;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getOpenTime() {
return openTime;
}
public void setOpenTime(String openTime) {
this.openTime = openTime;
}
public String getSfz() {
return sfz;
}
public void setSfz(String sfz) {
this.sfz = sfz;
}
public double getJe() {
return je;
}
public void setJe(double je) {
this.je = je;
}
//存款方法
public void ck(double je){
this.je=this.je+je;//存入的金額加上原有的金額
}
//取款方法
public void qk(double je){
if(je>this.je){//取款金額大於余額
System.out.println("存款余額不足");
}else{
this.je=this.je-je;//原有的金額減去取出的金額
}
}
public static void main(String[] args) {
ZH zh = new ZH();//初始化一個賬戶信息
zh.setJe(10000.0);//向zh賬戶添加余額
zh.setOpenTime("2013.12.3");//向zh賬戶添加開發時間
zh.setPassword("123456");//向zh賬戶添加密碼
zh.setSfz("123456789");//向zh賬戶添加身份證
zh.setZh("zhangsan");//向zh賬戶添加賬號
System.out.println("歡迎光臨模擬銀行");
Scanner scan = new Scanner(System.in);
int count=0;//記錄輸入錯誤的次數
while(1==1){//循環
System.out.println("請輸入賬號");
String zhm=scan.next();
System.out.println("請輸入密碼");
String mm=scan.next();
if(zhm.equals(zh.getZh()) && mm.equals(zh.getPassword())){//輸入的信息與zh賬戶信息的密碼和賬號一致
while(1==1){
System.out.println("當前余額為:"+zh.getJe()+"元。請選擇操作:1.存款;2.取款;3.退出(只能輸入數字)");
String cz=scan.next();
switch (Integer.parseInt(cz)) {
case 1:
System.out.println("請輸入存款金額(輸入小數)");
double ckje=scan.nextDouble();
zh.ck(ckje);
System.out.println("實施存款:"+ckje+"元,當前余額為"+zh.getJe()+"元");
break;
case 2:
System.out.println("請輸入取款金額(輸入小數)");
double qkje=scan.nextDouble();
zh.qk(qkje);
System.out.println("實施取款:"+qkje+"元,當前余額為"+zh.getJe()+"元");
break;
case 3:
break;
default:
System.out.println("暫無此功能");//輸入1或者2、3以外的操作
break;
}
if("3".equals(cz)){
break;
}
}
System.out.println("退出操作");
break;
}else{
if(count>=3){
System.out.println("已輸入錯誤三次,賬號被鎖");
break;//結束循環
}else{
System.out.println("賬號或密碼錯誤,請重新輸入");
count++;//錯誤一次count+1
continue;//進入下次循環
}
}
}
}
}
⑷ Java語言程序設計:設計銀行賬戶類,屬性包括賬號、儲戶名稱、開戶時間、身份證號碼、存款余額等
寫個例子吧,既沒有分,又不付費。。。。真的是。。
public class account{
public static int serviceNum;
private String account;
private String password;
......
public String getAccount(){
return this.account;
}
public void setAccount(String account){
this.account = account;
}
public String getPassword(){
return this.password;
}
public void setPassword(String password){
this.password = password
}
public Account(String account,String password){
this.account = account;
this.password = password;
}
public Account(String account){
this.account = account;
}
@overrite
public String toString(){
return this.account + "-" + this.password;
}
}
⑸ 用JAVA語言編寫程序,模擬銀行賬戶功能。要有: 屬性:賬號、儲戶姓名、地址、存款余額、最小余額。
package com.cshr.test;
public class bank {
private String card;//賬號
private String uname;//儲戶姓名
private String address;//地址
private double money;//存款余額
public static final double minMoney=0;//最小余額
public bank(){}
public String getCard() {
return card;
}
public void setCard(String card) {
this.card = card;
}
public String getUname() {
return uname;
}
public void setUname(String uname) {
this.uname = uname;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public double getMoney() {
return money;
}
public void setMoney(double money) {
this.money = money;
}
public static double getMinmoney() {
return minMoney;
}
}
package com.cshr.test;
import java.util.List;
import org.hibernate.Session;
import com.utils.HibernateSessionFactory;
public class bankDao {
//存款
public void addMoney(double money,double Sqlmoney,String card){
Session session=HibernateSessionFactory.getSession();
try{
session.beginTransaction();
String hql="update bank b set b.money+="+money+Sqlmoney+" where b.card='"+card+"'";
session.createQuery(hql).executeUpdate();
session.beginTransaction().commit();
}catch(Exception e){
e.printStackTrace();
session.beginTransaction().rollback();
}finally{
HibernateSessionFactory.closeSession();
}
}
//取款
public void delMoney(double money,double Sqlmoney,String card){
Session session=HibernateSessionFactory.getSession();
try{
session.beginTransaction();
String hql="update bank b set b.money+="+(Sqlmoney-money)+" where b.card='"+card+"'";
session.createQuery(hql).executeUpdate();
session.beginTransaction().commit();
}catch(Exception e){
e.printStackTrace();
System.out.println("取款失敗");
session.beginTransaction().rollback();
}finally{
HibernateSessionFactory.closeSession();
}
}
//查詢所有
public List<bank> selectfind(){
Session session=HibernateSessionFactory.getSession();
session.beginTransaction();
String hql="select b from bank b ";
List<bank> list=session.createQuery(hql).list();
return list;
}
}
⑹ 在java中,聲明銀行賬戶類,成員變數包括賬號,儲戶姓名,開戶時間,身份證號碼,存款余額等賬戶信息,成
import java.util.Scanner; public class bank
{ int number,id; int year,month,day; float money; String name; void set(int y,int m,int d)
{ year=y; month=m; day=d; } public String toString()
{ return year+"年"+month+"月"+day+"日"; } public float money1(int n)
{ money=money+n; return money; } public float money2(int x)
{ if(money<x) return 0; money=money-x; return money; } public static void main(String args[])
{ bank b=new bank(); b.set(2009,8,6); b.money=0; b.number=1; b.id=20102; b.name="張三"; System.out.println("用戶名:"+b.name);
System.out.println("身份證號:"+b.id); System.out.println("開戶日期是:"+b.toString()); System.out.print("請輸入存入的數額:"); Scanner sc = new Scanner(System.in); int i = sc.nextInt(); b.money1(i); System.out.print("賬戶余額:"+b.money); System.out.println(); System.out.print("請輸入取款余額:"); Scanner cc = new Scanner(System.in); int j = cc.nextInt(); b.money2(j); System.out.print("賬戶余額:"+b.money); } }
⑺ 求助!銀行排隊叫號程序,java待完善。。。
importjava.awt.Color;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjava.awt.event.WindowAdapter;
importjava.awt.event.WindowEvent;
importjavax.swing.ButtonGroup;
importjavax.swing.JButton;
importjavax.swing.JFrame;
importjavax.swing.JLabel;
importjavax.swing.JPanel;
importjavax.swing.JTextField;
{
inttotal=0,now=0;
booleanis1Ready=false,is2Ready=false,is3Ready=false;
intcall1,call2,call3;
JFramejf;
JLabeljr,jl,jl1,j2,jl2,j3,jl3;
JTextFieldjr4;
JButtonjb,jb1,jb2,j1;
JButtonworkBut1,workBut2,workBut3;
JPaneljp,jp1,jp2;
publicBankWaiting(){
setLayout(null);
jf=newJFrame("銀行叫號程序");//窗體
jr=newJLabel("請**號到*號窗口辦理業務");
jr.setBounds(300,10,800,50);
jr.setForeground(Color.red);
j1=newJButton("取號");
j1.addActionListener(this);
jr4=newJTextField("歡迎");
jr4.setEditable(false);
ButtonGroupbg=newButtonGroup();
bg.add(j1);
jp=newJPanel();
jl=newJLabel("一號窗口");
jl1=newJLabel("一號窗口,歡迎你!");
jb=newJButton("下一位");
workBut1=newJButton("開始辦理");
workBut1.addActionListener(this);
jb.addActionListener(this);
jp.setBackground(Color.pink);
jp.setSize(200,80);//大小
jp.setLocation(20,120);//位置
jf.setLayout(null);
jp1=newJPanel();
j2=newJLabel("二號窗口");
jl2=newJLabel("二號窗口,歡迎你!");
jb1=newJButton("下一位");
workBut2=newJButton("開始辦理");
jb1.addActionListener(this);
workBut2.addActionListener(this);
jp1.setBackground(Color.pink);
jp1.setSize(200,80);//大小
jp1.setLocation(250,120);//位置
jf.setLayout(null);
jp2=newJPanel();
j3=newJLabel("三號窗口");
jl3=newJLabel("三號窗口,歡迎你!");
jb2=newJButton("下一位");
workBut3=newJButton("開始辦理");
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(newWindowAdapter(){
publicvoidwindowClosing(WindowEvente){
System.exit(0);
}
});
}
publicvoidactionPerformed(ActionEvente){
Strings="";
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;
}
}elseif(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;
}
}elseif(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;
}
}elseif(e.getSource()==workBut2){
if(is2Ready){
s=call2+"號顧客正在辦理業務。。。";
jl2.setText(s);
is2Ready=false;
}
}elseif(e.getSource()==workBut3){
if(is3Ready){
s=call3+"號顧客正在辦理業務。。。";
jl3.setText(s);
is3Ready=false;
}
}
}
publicbooleanhasCustomers(){
if(now<total){
returntrue;
}else{
returnfalse;
}
}
publicstaticvoidmain(String[]args){
newBankWaiting();
}
}
⑻ JAVA怎麼定義方法 setLocation(int, int)
寫一個隊列,就是生產者和消費者類型的倉庫,下面proct是產品類,你可以把它改成號碼
public class SyncStack {
private int rear;//隊尾
private int front;//隊頭
private Proct[] queArray;//隊列
public SyncStack(int s) {
front = 0;
queArray = new Proct[s];
rear = -1;
}
//入隊列
public synchronized void push(Proct proct) {
while (rear == queArray.length - 1) {
try {
this.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
this.notifyAll();
queArray[rear + 1] = proct;
rear++;
}
//出隊列
public synchronized Proct pop() {
while (front == rear + 1) {
try {
this.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
front++;
this.notifyAll();
return queArray[front-1];
}
}
⑼ java作業:創建一個銀行,銀行裡面有5個賬戶(賬號,密碼,錢)。要求:1、開戶;2、開戶以後才能
兩個實體類
實體類1:
public class Bank {
private List<Card> list;
public Bank() {
super();
}
public Bank(List<Card> list) {
super();
this.list = list;
}
public List<Card> getList() {
return list;
}
public void setList(List<Card> list) {
this.list = list;
}
}
實體類2:
public class Card {
private String id;
private String password;
private String isOpen; //判斷是否開戶 0開戶 1沒開戶
private double money;
public Card() {
super();
}
public Card(String id, String password, String isOpen ,double money) {
super();
this.id = id;
this.password = password;
this.isOpen = isOpen;
this.money = money;
}
public double getMoney() {
return money;
}
public void setMoney(double money) {
this.money = money;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getIsOpen() {
return isOpen;
}
public void setIsOpen(String isOpen) {
this.isOpen = isOpen;
}
@Override
public String toString() {
return "Card [id=" + id + ", password=" + password + ", isOpen=" + isOpen + ", money=" + money + "]";
}
}
邏輯處理類:
public class TestService {
public Bank addUserInfo(){
Card card = new Card("1","1","0",10000);
Card card1 = new Card("2","2","1",20000);
Card card2 = new Card("3","3","1",30000);
Card card3 = new Card("4","4","1",40000);
Card card4 = new Card("5","5","1",50000);
List<Card> list = new ArrayList<>();
list.add(card);
list.add(card1);
list.add(card2);
list.add(card3);
list.add(card4);
Bank bank = new Bank();
bank.setList(list);
List<Card> list1 = bank.getList();
return bank;
}
public Card login(Bank bank , String id,String password){
Card card1 = null;
List<Card> list = bank.getList();
for (Card card : list) {
if(id.equals(card.getId()) && password.equals(card.getPassword())){
card1 = card;
break;
}
}
return card1;
}
}
測試類:
public class Test {
public static void main(String[] args) {
TestService service = new TestService();
Bank bank = service.addUserInfo();
System.out.println("****************************");
System.out.println("*********歡迎進入銀行系統********");
System.out.println("****************************");
Scanner input = new Scanner(System.in);
System.out.println("請輸入卡號");
String id = input.next();
System.out.println("請輸入密碼");
String password = input.next();
Card card = service.login(bank , id, password);
if(card != null){
System.out.println("登陸成功");
}else{
System.out.println("登陸失敗 ");
}
System.out.println("請選擇你要的操作");
System.out.println("1.取款 2.查詢余額 3.注銷");
Scanner input1 = new Scanner(System.in);
String aa = input1.next();
if(aa.equals("3")){
System.out.println("注銷成功");
}else if(aa.equals("2")){
System.out.println("卡號是:"+card.getId()+"余額是:"+card.getMoney());
}else if(aa.equals("1")){
if(card.getIsOpen().equals("1")){
System.out.println("對不起您的卡號沒有開戶,不能取款");
}else{
System.out.println("請輸入取款金額");
Scanner input2 = new Scanner(System.in);
String bb = input2.next();
if(Double.parseDouble(bb) > card.getMoney() ){
System.out.println("余額不足");
}else{
card.setMoney(card.getMoney() - Double.parseDouble(bb) );
System.out.println("取款成功,取款金額"+bb+"余額是:"+card.getMoney());
}
}
}
}
}
這個是我簡單寫的邏輯,看你的需求應該就是這樣,沒有牽扯到資料庫。。運行效果如圖:
需要源碼的話你把郵箱發給我,具體邏輯你還需要自己再修改一下,我只是把基本功能寫出來了,還有開戶操作我還沒寫,我只是把1這個用戶默認成開戶狀態了。