练习1:(面向对象基础语法)

写一个账户类(Account),

属性: id:账户号码 长整数

password:账户密码

name:真实姓名

personId:身份证号码 字符串类型

email:客户的电子邮箱

balance:账户余额

方法: deposit:存款方法,参数是double型的金额

withdraw:取款方法,参数是double型的金额

练习2:(封装)

将Account类作成完全封装,注意:要辨别每个属性的set/get方法是否需要公开

为这两种用户编写相关的类

同时要求编写Bank类,属性:

1.当前所有的账户对象的集合,存放在数组中

2.当前账户数量

方法:

1.用户开户,需要的参数:id,密码,密码确认,姓名,身份证号码,邮箱,账户类型(int),返回新创建的Account对象

2.用户登录,参数:id,密码 返回Account对象,提示 用s1.equals(s2)判断s1和s2两个字符串内容是否相等

3.用户存款,参数:id,存款数额,返回修改过的Account对象

4.用户取款,参数:id,取款数额,返回修改过的Account对象

5.设置透支额度 参数:id,新的额度  ,返回修改过的Account对象.这个方法需要验证账户是否是信用账户

用户会通过调用Bank对象以上的方法来操作自己的账户,请分析各个方法需要的参数

另外,请为Bank类添加几个统计方法

1.统计银行所有账户余额总数

2.统计所有信用账户透支额度总数

写个主方法测试你写的类

package Encapsulation;

import java.util.Scanner;

public class Account {
private long accoundId;//账户号码
private String passsWord;//密码
private String name;//真实姓名
private String personId;//身份证号码
private String email;//邮箱
private double balance;//账户余额
private char isCredit;//记录是否是信用账户
private double overDraft;//是信用卡用户,透支额度
private double overDraftMoney;//记录已经透支多少?
//无参构造法函数方便使用
public Account(){}
public Account(long accoundId,String passsWord,String name,String personId,String email,double balance){
//构造方法,用于初始化
this.accoundId = accoundId;
this.passsWord = passsWord;
this.name = name;
this.personId = personId;
this.email = email;
this.balance = balance;
}
//显示账户信息
public void show(){
System.out.println(accoundId+"\t"+name+"\t"+personId+"\t"+email+"\t"+balance);
}
//存钱方法
public void deposit(){
do {
System.out.println("请输入存款额度:");
Scanner input=new Scanner(System.in);
double depositAmount=input.nextDouble();
if(depositAmount <= 0){
System.out.println("存款失败");
break;
}else{
this.balance = this.balance + depositAmount;
System.out.println("存款成功");
System.out.println("账户余额:"+this.getBalance());
System.out.println("是否继续?y/n");
char isGo = input.next().charAt(0);
if(isGo == 'y'){
continue;
}else{
System.out.println("已安全退出");
break;
}
}
} while (true);
}
//取款方法
public double withdraw(){
do {
Scanner input = new Scanner(System.in);
System.out.println("请输入取款金额");
double withdrawAmount = input.nextDouble();
//判断取款金额是正确的
//金额必须是大于0正数,并且小于账户余额
if(withdrawAmount > 0 && withdrawAmount <= this.balance){
this.balance = this.balance - withdrawAmount;
System.out.println("取款成功,账户余额:"+this.getBalance());
System.out.println("是否继续?y/n");
char isGo = input.next().charAt(0);
if(isGo == 'y'){
continue;
}else{
System.out.println("已安全退出");
return this.balance;
}
}else{
System.out.println("取款失败");
return this.balance;
}
} while (true);
}
public long getAccoundId() {
return accoundId;
}
public void setAccoundId(long accoundId) {
this.accoundId = accoundId;
}
//用户密码是谁都看不见的,不可以通过方法显示
public String getPasssWord() {
return passsWord;
}
//返回boolean以判断客户是否输入正确的长度
public boolean setPasssWord(String passsWord) {
if(passsWord.length() != 6){
System.out.println("密码长度不够,请输入6位数的密码:");
return false;
}else{
this.passsWord = passsWord;
return true;
}
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPersonId() {
return personId;
}
public void setPersonId(String personId) {
this.personId = personId;
}
public String getEmail() {
return email;
}
//email可能是错误的,在设置的时候就判断
public boolean setEmail(String email) {
int a = email.indexOf('@');
int d = email.indexOf('.');
if(a>0 && d>(a+1) && (email.length()-d) >= 2){
this.email = email;
return true;
}
else{
return false;
}
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}

}

//主类(无main函数)

package Encapsulation;

import java.io.PrintStream;
import java.util.Scanner;
import ClassTest.SuperMarketManage;

public class ABCBank {
Account account[]=new Account[100];
Scanner input=new Scanner(System.in);
Account account2;
PrintStream outPut;
int accountNum;//记录已开户账户的数量
double moneyAll;//记录所有账户的存款总额
double outMoney;//记录信用卡透支总额
long newCardNum;
int loginTimes = 1;

//中国农业银行主界面
public void mainView(){
int choice=0;
initData();

outPrint("欢迎进入ABCBank管理系统\n1.登录\n2.开户\n3.退出");
outPrint("请选择操作序列号:");
if(checkInputType()){
choice = input.nextInt();
if(choice == 1){
//登录成功后,把登录账户记录到account2里
account2 = login();
outPrint("请选择操作序列号:\n1.存款\n2.取款");
if(checkInputType()){
int choice1 = input.nextInt();
if(choice1 == 1){
//调用存款方法
account2.deposit();
}else if(choice1 == 2){
//调用取款方法
account2.withdraw();
}else{
outPrint("操作失误");
}
}
}else if (choice == 2) {
openAccount();
}else {
outPrint("已安全退出");
System.exit(0);
}
}
}
//初始化
public void initData(){
newCardNum=1111;
outPut=System.out;
account[0]=new Account(1111, "123456", "张海", "100125199503201548", "zhannghai@126.com", 200.00);
account[1]=new Account(1112, "123456", "黄道", "100125199503201548", "huangdao@126.com", 1000000.00);
account[2]=new Account(1113, "123456", "柳城", "100125199503201548", "liucheng@126.com", 20000.00);
accountNum=3;
}

//开户
public Account openAccount(){
do {
String pwd1;
account[accountNum]=new Account();
outPrint("请输入您的真实姓名:");
account[accountNum].setName(input.next());
outPrint("请输入您的身份证号码:");
account[accountNum].setPersonId(input.next());
//邮箱可能输入错误,判断,正确则赋值并返回true,错误,不赋值,返回false。
do {
outPrint("请输入您的邮箱:");
if(account[accountNum].setEmail(input.next())){
break;
}else{
outPrint("邮箱输入错误");
continue;
}
} while (true);
//密码可能长度不对,在封装里面做了判断,长度正确则赋值并返回true,长度错误,不赋值,返回false。
do {
outPrint("请输入您的密码");
pwd1=input.next();
if(account[accountNum].setPasssWord(pwd1)){
break;
}else{
continue;
}
} while (true);
outPrint("请再次输入您的密码");
String pwd2=input.next();
if(pwd2.equals(pwd1)){
long accoundId=newCardNum+accountNum;
outPrint("注册成功\n您的账号是:"+(accoundId));
account[accountNum].setAccoundId(accoundId);
return account[accountNum];
}else{
outPrint("两次输入密码不一致,请重新输入:");
continue;
}
} while (true);
}
//登录(成功后可以调用存款,取款方法,账户余额高于100000,则可以申请信用卡账户,信用卡可以透支10000)
public Account login(){
do {
System.out.println("请依次输入您的银行卡号和密码:(失败3次该卡会被锁定)");
long accountID = input.nextLong();
String pwd = input.next();
//调用核对登录用户名和密码方法
boolean isLoginSuccess = check_login(accountID, pwd);
if(isLoginSuccess){
System.out.println("登录成功");
for(int i = 0;i < accountNum;i++){
if(account[i].getAccoundId() == accountID ){
return account[i];
}
}
break;
}
else{
System.out.println("登录失败");
loginTimes++;
continue;
}
} while (loginTimes < 4);
return null;
}
//login核对用户登录账号密码
public boolean check_login(long accountID,String pwd){
for(int i = 0;i < accountNum;i++){
if(account[i].getAccoundId() == accountID){
if(account[i].getPasssWord().equals(pwd)){
return true;
}
}else{
continue;
}
}
return false;
}
//统计用户数据
public void countAllaccountIfo(){
double allMoney = 0.00;
for(int i=0;i<accountNum;i++){
allMoney+=account[i].getBalance();

}
outPrint("已注册账户总数量:"+accountNum);
outPrint("注册账户存储总金额:"+allMoney);
outPrint("信用卡用户透支总额:");
}
//输出方法(泛型)
public <T> void outPrint(T t){
outPut.println(t);
}
//判断输入是否为数字方法2
public boolean checkInputType(){
//可以用if(!input.hasNextInt){}来代替下面的语句
if (!input.hasNextInt()){
//hasNextInt是判断接下来输入的是否是int型
//nextline是让输入进入下一行(用来防止死循环——无限次判定,并且得到同样的结果)
input.nextLine();
return false;
}
else 
return true;
}
}

Jva实现银行系统的简写相关推荐

  1. Go 学习笔记(26)— Go 习惯用法(多值赋值,短变量声明和赋值,简写模式、多值返回函数、comma,ok 表达式、传值规则)

    1. 多值赋值 可以一次性声明多个变量,并可以在声明时赋值,而且可以省略类型,但必须遵守一定的规则要求. package main import "fmt"func main() ...

  2. 12个常用的javascript简写技巧---可以大大减少js代码量

    微信公众号 个人博客 知乎 本文是并非本人所写,只是我看了觉得对自己很有帮助,所以分享给大家,原文链接在最下面,谢谢观看. 1. 空(null, undefined)验证 当我们创建了一个新的变量,我 ...

  3. console.log 简写

    console.log 简写 平常代码调试总会用到console.log,但是每次写这么长也是很麻烦,就想着存一个简介一点的变量: 然后就随手写了下面代码: var a = 10;var log = ...

  4. CSS 背景(background)(背景颜色color、背景图片image、背景平铺repeat、背景位置position、背景附着、背景简写、背景透明、链接导航栏综合案例)

    1. 背景颜色(color) background-color:颜色值; 默认的值是 transparent 透明的 示例代码: <!DOCTYPE html> <html lang ...

  5. 【JNI】JNI中java类型的简写

         在JNI中,当我们使用GetFieldID/GetStaticFieldID或GetMethodID/GetStaticMethodID及定义JNINativeMethod等时,我们需要表示 ...

  6. CSS2简写和常用css总结笔记

    外边距 margin:1px 1px 1px 1px 简写margin:1px;            maigin:1px 2px 1px 2px 简写 margin:1px 2px;        ...

  7. Exchange企业实战技巧(5)配置OWA域名简写

    默认设置下,Exchange使用https://mail.contoso.com/owa访问邮箱.我们可以通过修改IIS设置,当输入http://mail.contoso.com或者mail.cont ...

  8. readline 库简写版本,测试可用

    /* 因为嵌入式的需求 所以有自定义命令行的需求,方便设备调试 没有使用readline gnu库因为有点大不方便移植,所以照着shell.c 和 ftp main.c 对代码需要使用的部分,做了重写 ...

  9. ipv6简写还原_用什么进制表示ipv6

    用什么进制表示 因为10进制表示时,使用0到9共十个数字来表示,而16进制需要在10进制原有的基础上多出6个数字,即需要多出11,12,13,14,15,这6个数字则采用字母的形式来表示,分别为: A ...

最新文章

  1. FF小股东美国起诉恒大 要求收回中国公司控制权
  2. 好程序员web前端分享js剪切板Clipboard.js 使用
  3. Android中使用ViewStub提高布局性能
  4. 深入浅出 RPC - 浅出篇+深入篇
  5. codeforces gym-101741 Subsequence Sum Queries 分治+离线
  6. java数组图片_在JAVA中定义图片数组
  7. linux内核分析实验三,linux内核分析第三次实验
  8. 解决yum锁定Another app is currently holding the yum lock; waiting for it to exit...
  9. 4后期盒子叫什么_考研:什么叫跨考专业?跨考专业的4大原因和存在3个方面的困难...
  10. 1006. 换个格式输出整数 (15)-PAT乙级真题
  11. 销售订单获取不到即时库存
  12. mysql for windows 64_MySQL 5.6 for Windows 解压缩版配置安装(win 10 64位亲测)附安装包下载链接...
  13. 编写一个UNIX文件系统
  14. 短信API接口怎么调用
  15. 日文输入键盘罗马字对应表
  16. PHP入门-简单博客编写
  17. 少有人走的路:心智成熟的旅程
  18. V831——AprilTag标签识别
  19. Axure 8 网页滚动效果+APP上下垂直拖动效果
  20. 安装python与编译工具vs code(中文版)和pycharm(中文版)

热门文章

  1. 直销现状:从奖金分配政策看直销
  2. 比原链BTM的bytomcli使用说明
  3. 苏银凯基消金获批筹建,三大股东上半年业绩“不尽人意”
  4. 《上海市专业技术职称(资格)评定与专业技术职务评聘相分离的暂行办法》
  5. 初学者学习微服务 需要了解哪些知识?该如何入门微服务?有哪些优质的教程可以学习?
  6. python模板注入_Python模板注入(SSTI)深入学习
  7. 关系型和非关系型数据库的区别
  8. 聊天界面-自适应文字
  9. matlab 常用函数和技巧
  10. word2007 不能输入中文解决方法