Java ATM take money code

Source: Internet
Author: User


Package com.eduask.test;


Import Java.util.Scanner;


public class ATM {

Static double money=0.0;//Create an account with an amount of 0.0

public static void Main (string[] args) {

Scanner sc=new Scanner (system.in);

for (;;) {

System.out.println ("Welcome to love to save the bank");

SYSTEM.OUT.PRINTLN ("Please select transaction type: 1 Save 2 withdraw money 3 Check balance 4 exit");

int Num=sc.nextint ();

if (num==1) {

System.out.println ("Your deposit amount is:");

Double m=sc.nextdouble ();

Add (m);

}else if (num==2) {

SYSTEM.OUT.PRINTLN ("Your withdrawal amount is:");

Double m=sc.nextdouble ();

if (M>money) {

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

}else{

if (m%100==0) {

Jian (m);

}else{

SYSTEM.OUT.PRINTLN ("The machine only provides 100 yuan par access");

}

}

}else if (num==3) {

Query ();

}else{

Break

}

}


}

/**

* Save money

*/

public static void Add (double m) {

Money+=m;

}

/**

* Withdraw Money

*/

public static void Jian (double m) {

Money-=m;

}

/**

* Check Balance

*/

public static void query () {

System.out.println ("Your balance is:" +money);

}


}


Java ATM take money code

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.