Simulate bank deposit java, simulate bank deposit and withdrawal business

The suspected violation of this floor has been folded by the system. Hide this floor to view this floor

public class Account { // Initialize deposit

float count = 0f;// current account balance

int money1;// deposit amount, int money2;// withdraw amount/*

* deposit

*/

public float saveMoney() {

count += money1;

return count;

} /*

* Withdrawal

*/

public float getMoney() {

if (count == 0) {

System.out.println("Your balance is not enough"); } else {

count -= money2;

System.out.println("Your balance is not enough"); }

return count;

}

}

/*

* Simulate bank deposit and withdrawal business

*/

import java.util.Scanner; public class TestBan {

public static void main(String[] args) {

boolean isOk = false;

Account st = new Account();

Scanner sc = new Scanner(System.in); do {

System.out.println("1. Deposit 2. Withdraw 0 exit");

System.out.print("Please select the business you need to do:");

int num = sc.nextInt();

switch (num) {

case 1:

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

st.money1 = sc.nextInt();

float a = st.saveMoney();

System.out.println("Successful deposit");

System.out.println("\n***The current balance is " + a + "Yuan***\n");

isOk = true;

break;

case 2:

System.out.print("Please enter the withdrawal amount: ");

st.money2 = sc.nextInt();

if (st.count == 0||st.count

System.out.println("Your balance is not enough\n");

} else {

float b = st.getMoney();

System.out.println("Withdrawal succeeded");

System.out.println("\n***The current balance is " + b + "Yuan***\n");

}

isOk = true;

break;

case 0:

System.out.println("Thank you for using!");

isOk = false;

break;

default:

break;

}

} while (isOk);

}

}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324138011&siteId=291194637