ATM shows up in an object-oriented way

Source: Internet
Author: User

This is the functional implementation section.

Import Java.util.Scanner;

ATM machine
public class Atmmachine {
User Information
Private UserInfo user;
Cash
private int cash;
Maximum cash capacity
public final int max_cash = 200000;
Access limit
public final int get_set_max = 2000;

Public Atmmachine () {
Pre-loading user information
This.user = new UserInfo ("J124", "123456", 500);
This.cash = 100000;
}

Run
public void Run () {
This.welcome ();
Boolean flag = This.login ();
if (flag) {
System.out.println ("Welcome, user" + this.user.getUsername () + "! ");
while (true) {
int choice = This.choicemenu ();
Switch (choice) {
Case 1:
This.query ();
Break
Case 2:
This.storemoney ();
Break
Case 3:
This.getmoney ();
Break
Case 4:
This.changepwd ();
Break
Case 5:
This.exit ();
Break
Default
System.out.println ("Sorry, no this option!") ");
Break
}
}
} else {
System.out.println ("Your account is frozen! Please go to the counter to handle! ");
}
}

Show Welcome
private void Welcome () {
System.out.println ("******************************");
System.out.println ("********* Huan * * * * * * recorded *********");
System.out.println ("******************************");
System.out.println ("********* Love to Save Bank atm*********");
System.out.println ("******************************");
System.out.println ("*****************version1.0***");
}

Login
Private Boolean login () {

for (int i = 0; i < 3; i++) {
Scanner scan = new Scanner (system.in);
System.out.println ("Please enter your account number:");
String InputName = Scan.next ();
System.out.println ("Please enter your password:");
String inputpwd = Scan.next ();
if (Inputname.equals (This.user.getUsername ())
&& inputpwd.equals (This.user.getPassword ())) {
return true;
} else {
SYSTEM.OUT.PRINTLN ("Wrong input! You also have "+ (2-i) +" Second Chance ");
}
}
return false;
}

Select Menu
private int Choicemenu () {
int choice = 0;
Scanner scan = new Scanner (system.in);
SYSTEM.OUT.PRINTLN ("Please select the action you want to perform:");
System.out.println ("1, Enquiry, 2, deposit, 3, withdrawal, 4, change of password; 5, exit");
Choice = Scan.nextint ();
return choice;
}

Check balance
private void query () {
Directly displays the account property value in the User object
System.out.println ("Your account's current balance is:" +this.user.getaccount ());

}

Saving
Private double Storemoney () {
1. Receiving user input
2, judgment--cannot be 0, cannot be negative, must be 100 multiples, cannot exceed the access limit, cannot exceed the cash capacity--gives the hint
3, judging through-plus cash, plus balance
Double sum=0; Sum of money and balance deposited by the user
while (true) {
Scanner s=new Scanner (system.in);
System.out.println ("Please enter the amount of money stored:");
int Cun=s.nextint ();
if (cun%100!=0) {
System.out.println ("The deposited money must be a multiple of 100, please re-enter:"); continue;
}
else if (cun<=0) {
SYSTEM.OUT.PRINTLN ("You entered the money in error, please re-enter"); continue;
}
else if (cun>this. Get_set_max) {
System.out.println ("Only a maximum of 2000 yuan can be deposited in a single time, please re-enter"); continue;
}
else{
System.out.println ("Deposit success, your balance is" + (Cun+this.user.getaccount ()));
Sum=cun+this.user.getaccount ();
return sum;
} (there is a problem here, no savings after the balance changes)
}
}
Withdrawal
private void Getmoney () {
while (true) {
Scanner s=new Scanner (system.in);
System.out.println ("Please enter the amount of money to be taken:");
int Qu=s.nextint ();
if (This.user.getAccount ()-qu<0) {
System.out.println ("Your account balance is insufficient, please re-enter"); continue;
}
else if (qu%100!=0) {
SYSTEM.OUT.PRINTLN ("You entered the wrong, must be a multiple of 100"); continue;
}
else if (qu>this. Get_set_max) {
System.out.println ("One-time withdrawal of up to 2000 yuan, please re-enter"); continue;
}
else{
System.out.println ("Withdrawal success, withdrawals" +qu+ "Yuan");
System.out.println ("Current balance of account" + (This.user.getAccount ()-qu));
}
} (This is also the problem above, there is no change in balance after the money is taken)
}
Change Password
private void Changepwd () {
while (true) {
Scanner s=new Scanner (system.in);
System.out.println ("Please enter the original password");
String Psw=s.next ();
if (Psw.equals (This.user.getPassword ())) {
Scanner w=new Scanner (system.in);
System.out.println ("Please enter the original password again");
String Psw1=w.next ();
if (Psw1.equals (This.user.getPassword ())) {
System.out.println ("Please enter a new password");
Scanner x=new Scanner (system.in);
String Xin=x.next ();
System.out.print ("Successful password modification");
}
else{
SYSTEM.OUT.PRINTLN ("Password inconsistent, please re-enter");
}
}

else{
System.out.print ("The password you entered is inconsistent with the original password, please re-enter");
}
}
}

Exit
private void exit () {
SYSTEM.OUT.PRINTLN ("Thank you for your use!") Please accept your card! ");
System.exit (0);
}

}

ATM shows up in an object-oriented way

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.