ATM Programming (Java)

Source: Internet
Author: User


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 ();

}


/***

* Welcome Screen

*

*/

public static void Welcome () {

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

SYSTEM.OUT.PRINTLN ("********* Welcome into ********");

SYSTEM.OUT.PRINTLN ("********* Construction Bank *********");

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

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

}

/*****

*

* Landing judgment

*

*/

private static void Login () {

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

System.out.println ("Please enter your account:");

String input_username = Scanner.next ();

System.out.println ("Please enter password:");

String Input_password = Scanner.next ();

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

System.out.println ("The account or password is wrong!) the input opportunity is left" + (i-1) + "Times");

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

SYSTEM.OUT.PRINTLN ("Error entered 3 times, swallowed card, please contact customer service ...");

Break

}else {

System.out.println ("Landing success!");

ShowMenu ();

Break

}

}

}

/***

*

* Operation Menu

*

*/

private static void ShowMenu () {

while (Iscontinue.equals ("Y")) {

SYSTEM.OUT.PRINTLN ("operation is as follows \ 1.) 2. Deposit 3. Withdrawal 4. Change Password 5. Exit");

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 ("illegal input");

}

}

}



/***

*

* Check Balance

*

*/

private static void Showmonery () {

System.out.println ("The current balance is:" +monery);

Iscontinue ();

}

/***

*

* Deposit

*

*/

private static void Inputmonery () {

System.out.println ("Please enter the amount to deposit:");

Double temp_monery = scanner.nextdouble ();

if (temp_monery<=0) {

SYSTEM.OUT.PRINTLN ("Illegal input amount");

}else if (temp_monery>10000) {

System.out.println ("a single deposit of up to 10,000 Yuan");

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

SYSTEM.OUT.PRINTLN ("The amount of deposit must be a multiple of 100");

}else{

Monery +=temp_monery;

System.out.println ("Deposit success! Current balance:" +monery);

}

Iscontinue ();

}

/***

* Withdrawals

*

*/

private static void Outmonery () {

System.out.println ("Please enter the amount to be withdrawn:");

Double outmonery = scanner.nextdouble ();

if (Outmonery <=0) {

System.out.println ("Enter the amount of the withdrawal illegally");

}else if (outmonery>monery) {

SYSTEM.OUT.PRINTLN ("Insufficient balance!");

}else if (outmonery>5000) {

System.out.println ("a single withdrawal cannot exceed 5000 yuan");

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

SYSTEM.OUT.PRINTLN ("The amount of withdrawal must be a multiple of 100");

}else{

Monery-=outmonery;

System.out.println ("Withdrawal successful!"); The current balance is: "+monery);

}

Iscontinue ();

}

/***

*

* Modify; Change password

*/

private static void Modifymonery () {

System.out.println ("Please enter the old password:");

String Temp_password = Scanner.next ();

if (!temp_password.equals (password)) {

System.out.println ("Old password is not right!" Old password is "+password");

}else{

System.out.println ("Please enter a new password:");

String newpass = Scanner.next ();

System.out.println ("Please enter your new password again");

String newpass2 = Scanner.next ();

if (!newpass.equals (Newpass2)) {

System.out.println ("Two times input new password inconsistent!");

}else{

Password = newpass;

SYSTEM.OUT.PRINTLN ("Change password successfully!"); The current password is: "+password);

}

}

Iscontinue ();

}

/***

*

* Exit

*/

private static void layout () {

System.out.println ("Exit succeeded!");

System.exit (0);

}

/****

*

* Determine whether to continue

*/

private static void Iscontinue () {

System.out.println ("Do you want to continue?" ( y/n) ");

Iscontinue = Scanner.next ();

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

SYSTEM.OUT.PRINTLN ("program end!");

System.exit (0);

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

SYSTEM.OUT.PRINTLN ("illegal input");

Iscontinue ();

}

}


}



This article is from the "ATM Program Design" blog, reproduced please contact the author!

ATM Programming (Java)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.