Bank项目-java

在此献上大一下做的小项目,我的Java之路正式开启~~~

(注意:用*****隔开的表示分开写的,分别建立的几个.class文件。分了两个包,一个bank,一个banktest,而banktest里只有一个.class文件,

那就是测试用的,本来想加界面的,尝试了好多方式,因为不能实现界面的切换,暂时搁置了,银行的开户也是的,当时还没学(也没自学)数据库,

暂时无法实现开户并存储,下次登录还能有此用户的功能,也搁置了。)

  1 package bank;
  2 
  3 public class bankchaxun {
  4 public void chaxun(User[] cus){
  5 bankdenglu a=new bankdenglu();
  6 int zhanghao=a.denglu(cus);
  7 if(0!=zhanghao){
  8 System.out.println("姓名:"+cus[zhanghao].getname());
  9 System.out.println("账号:"+cus[zhanghao].getcard());
 10 System.out.println("密码:"+cus[zhanghao].getmima());
 11 System.out.println("余额:"+cus[zhanghao].getyue());
 12 }
 13 }
 14 
 15 }
 16 
 17 **************************************************
 18 
 19 package bank;
 20 
 21 import java.awt.*;
 22 import java.awt.event.*;
 23 import javax.swing.*;
 24 
 25 import java.util.Scanner;
 26 
 27 
 28 public class bankcunkuan{
 29 
 30 Scanner in = new Scanner(System.in);
 31 
 32 public void cunkuan(User[] cus){
 33 
 34 bankdenglu a=new bankdenglu();
 35 int zhanghao=a.denglu(cus);
 36 if(0!=zhanghao){
 37 System.out.println("输入存款金额:");
 38 double money=in.nextDouble();
 39 money+=cus[zhanghao].getyue();
 40 cus[zhanghao].setyue(money);
 41 System.out.println("银行卡余额为:"+cus[zhanghao].getyue());    
 42 }
 43 }
 44 
 45 **************************************************
 46 
 47 package bank;
 48 
 49 import java.util.Scanner;
 50 
 51 public class bankdenglu {
 52 Scanner in = new Scanner(System.in);
 53 public int denglu(User[] cus){
 54 
 55 System.out.println("请输入账号");
 56 int zhanghao=in.nextInt();
 57 if(zhanghao<1000||zhanghao>=10000||""==(cus[zhanghao].getmima())){
 58 System.out.println("输入账号不存在");
 59 return 0;
 60 }else{
 61 System.out.println("请输入密码");
 62 
 63 String mima=in.next();
 64 
 65 if((cus[zhanghao].getmima()).equals(mima)){
 66 System.out.println("登录成功");
 67 return zhanghao;
 68 }
 69 else{
 70 System.out.println("密码错误");
 71 return 0;
 72 }
 73 }
 74 
 75 }
 76 
 77 }
 78 
 79 **************************************************
 80 
 81 package bank;
 82 
 83 import java.util.Scanner;
 84 
 85 public class bankmenu {
 86 Scanner in = new Scanner(System.in);
 87 
 88 public void menu(){
 89 User[] cus =new User[10000];
 90 cus[1000]=new User("tiantian",1000,"123456",123);
 91 
 92 bankcunkuan b=new bankcunkuan();
 93 bankqukuan c=new bankqukuan();
 94 bankchaxun d=new bankchaxun();
 95 bankxiugai e=new bankxiugai();
 96 
 97 System.out.println("\t银行管理系统");
 98 System.out.println("***************************");
 99 System.out.println("\t1.------存款");
100 System.out.println("\t2.------取款");
101 System.out.println("\t3.------查询");
102 System.out.println("\t4.------修改密码");
103 System.out.println("***************************");
104 System.out.println("请输入服务项目:");
105 while(true){
106 
107 int key=in.nextInt();
108 switch(key){
109 case 1:b.cunkuan(cus);break;
110 case 2:c.qukuan(cus);break;
111 case 3:d.chaxun(cus);break;
112 case 4:e.xiugai(cus);break;
113 default:System.out.println("输入不正确,请重新输入");
114 }
115 if(key>=1&&key<=4){
116 break;
117 }
118 }
119 
120 }
121 }
122 
123  *************************************************
124 package bank;
125 
126 import java.util.Scanner;
127 
128 public class bankqukuan {
129 
130 Scanner in = new Scanner(System.in);
131 
132 public void qukuan(User[] cus){
133 bankdenglu a=new bankdenglu();
134 int zhanghao=a.denglu(cus);
135 if(0!=zhanghao){
136 System.out.println("请输入取款金额");
137 
138 double money=in.nextDouble();
139 if(money<=cus[zhanghao].getyue()){
140 double yue=cus[zhanghao].getyue();
141 yue-=money;
142 cus[zhanghao].setyue(yue);
143 System.out.println("取款成功");
144 System.out.println("银行卡余额为:"+cus[zhanghao].getyue());
145 System.exit(0);
146 }
147 else {
148 System.out.println("余额不足");
149 
150 }
151 }
152 }
153 
154 }
155 
156 **************************************************
157 
158 package bank;
159 
160 import java.util.Scanner;
161 
162 public class bankxiugai {
163 Scanner in = new Scanner(System.in);
164 public void xiugai(User[] cus){
165 bankdenglu a=new bankdenglu();
166 int zhanghao=a.denglu(cus);
167 if(0!=zhanghao){
168 System.out.println("请输入新密码");
169 String mima=in.nextLine();
170 cus[zhanghao].setmima(mima);
171 System.out.println("修改完成");
172 }
173 }
174 }
175 
176 **************************************************
177 
178 package bank;
179 
180 public class User {
181 
182 private String name = "";
183 private int card=1000;
184 private String mima = "";
185 private double yue=0;
186 
187 public User(String name,int card,String mima,double yue){
188 this.name=name;
189 this.card=card;
190 this.mima=mima;
191 this.yue=yue;
192 }
193 
194 public void setname(String name){
195 this.name=name;
196 }
197 public void setcard(int card){
198 this.card=card;
199 }
200 public void setmima(String mima){
201 this.mima=mima;
202 }
203 public void setyue(double yue){
204 this.yue=yue;
205 }
206 
207 public String getname(){
208 return name;
209 }
210 public int getcard(){
211 return card;
212 }
213 public String getmima(){
214 return mima;
215 }
216 public double getyue(){
217 return yue;
218 }
219 }
220 
221 **************************************************
222 
223 package bankTest;
224 
225 import javax.swing.*;
226 
227 import java.awt.*;
228 import java.awt.event.*;
229 
230 import bank.User;
231 import bank.bankchaxun;
232 import bank.bankcunkuan;
233 import bank.bankmenu;
234 import bank.bankqukuan;
235 import bank.bankxiugai;
236 
237 public class test {
238 
239 public static void main(String[] args){
240 bankmenu d=new bankmenu();
241 d.menu();
242 
243 Window win = new Window();
244 //    win.setBounds(300, 200, 500, 500);//x,y,width,height设置窗口的位置及大小
245 
246 win.setTitle("银行系统");
247 
248 }
249 
250 
251 }

 =============================================================================================

源代码链接http://pan.baidu.com/s/1pKhYKhP

 

posted @ 2015-11-06 16:31  tt香薷  阅读(1975)  评论(0编辑  收藏  举报