码迷,mamicode.com
首页 > 编程语言 > 详细

ATM程序设计(java)

时间:2017-04-12 05:00:12      阅读:279      评论:0      收藏:0      [点我收藏+]

标签:password   程序设计   welcome   private   package   


package com.authr.day2;


import java.util.Scanner;


public class ATM2 {

private static String username ="admin";

private static String password= "123";

private static double monery = 10000;

private static String isContinue="y";

static Scanner scanner  = new Scanner(System.in);

public static void main(String[] args) {

welcome();

Login();

}


/***

* 欢迎界面

*/

public static void welcome(){

System.out.println("**********************************");

System.out.println("*********    欢迎进入          ********");

System.out.println("*********  中国建设银行     *********");

System.out.println("*************    Version1.0*******");

System.out.println("**********************************");

}

/*****

* 登陆判断

*/

private static void Login() {

for (int i = 3; i >0; i--) {

System.out.println("请输入账号:");

String input_username = scanner.next();

System.out.println("请输入密码:");

String input_password = scanner.next();

if((!input_username.equals(username) || !input_password.equals(password))&&(i-1)>0 ){

System.out.println("账号或密码错误!输入机会还剩下"+(i-1)+"次");

}else if((i-1)==0){

System.out.println("错误输入3次,已吞卡,请联系客服.....");

break;

}else {

System.out.println("登陆成功!");

showMenu();

break;

}

}

}

   

/***

* 操作菜单

*/

private static void showMenu() {

while(isContinue.equals("y")){

System.out.println("操作如下\n 1.查询  2.存款  3.取款  4.修改密码  5.退出");

int code = scanner.nextInt();

switch(code){

case 1:

showMonery();

break;

case 2:

inputMonery();

break;

case 3:

outMonery();

break;

case 4:

modifyMonery();

break;

case 5:

layout();

break;

default:

System.out.println("非法输入");

}

}

}



/***

     *

     * 查询余额

     * 

     */

private static void showMonery() {

System.out.println("当前余额为:"+monery);

isContinue();

}

/***

* 存款

*/

private static void inputMonery() {

System.out.println("请输入要存款的金额:");

double temp_monery = scanner.nextDouble();

if(temp_monery<=0){

System.out.println("输入金额非法");

}else if(temp_monery>10000){

System.out.println("单次存款最高1万元");

}else if(temp_monery%100 !=0){

System.out.println("存款的金额必须是100的倍数");

}else{

monery +=temp_monery;

System.out.println("存款成功!当前余额为:"+monery);

}

isContinue();

}

/***

* 取款

*/

private static void outMonery() {

System.out.println("请输入要取款的金额:");

double outMonery = scanner.nextDouble();

if(outMonery <=0){

System.out.println("输入取款的金额非法");

}else if(outMonery>monery){

System.out.println("余额不足!");

}else if(outMonery>5000){

System.out.println("单次取款不能超过5000元");

}else if(outMonery %100 !=0){

System.out.println("取款的金额必须为100的倍数");

}else{

monery -=outMonery;

System.out.println("取款成功!当前余额为:"+monery);

}

isContinue();

}

/***

* modify;修改密码

*/ 

private static void modifyMonery() {

System.out.println("请输入旧密码:");

String temp_password = scanner.next();

if(!temp_password.equals(password)){

System.out.println("旧密码不对!旧密码为"+password);

}else{

System.out.println("请输入新密码:");

String newpass = scanner.next();

System.out.println("请再次输入新密码");

String newpass2 = scanner.next();

if(!newpass.equals(newpass2)){

System.out.println("两次输入新密码不一致!");

}else{

password = newpass;

System.out.println("修改密码成功!当前密码为:"+password);

}

}

isContinue();

}

/***

* 退出

*/

private static void layout() {

System.out.println("退出成功!");

System.exit(0);

}

/****

* 判断是否继续

*/

private static void isContinue(){

System.out.println("是否继续?(y/n)");

isContinue = scanner.next();

if(isContinue.equals("n")){

System.out.println("程序结束!");

System.exit(0);

}else if(!isContinue.equals("y") && !isContinue.equals("n")){

System.out.println("非法输入");

isContinue();

}

}


}



本文出自 “ATM程序设计” 博客,转载请与作者联系!

ATM程序设计(java)

标签:password   程序设计   welcome   private   package   

原文地址:http://12815762.blog.51cto.com/12805762/1915020

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!