用eclipse写一个atm系统
时间: 2023-09-23 19:11:12 浏览: 100
ATM系统[eclipse]
好的,下面是一个简单的ATM系统的JAVA代码,使用Eclipse开发工具:
```java
import java.util.Scanner;
public class ATMSystem {
static Scanner input = new Scanner(System.in);
static double balance = 10000;
public static void main(String[] args) {
System.out.println("Welcome to ATM System!");
while (true) {
System.out.println("Please select an option:");
System.out.println("1. Check Balance");
System.out.println("2. Withdraw");
System.out.println("3. Deposit");
System.out.println("4. Exit");
int option = input.nextInt();
switch (option) {
case 1:
checkBalance();
break;
case 2:
withdraw();
break;
case 3:
deposit();
break;
case 4:
System.out.println("Thank you for using ATM System!");
System.exit(0);
break;
default:
System.out.println("Invalid option. Please select again.");
break;
}
}
}
public static void checkBalance() {
System.out.println("Your balance is " + balance);
}
public static void withdraw() {
System.out.println("Please enter the amount to withdraw:");
double amount = input.nextDouble();
if (amount > balance) {
System.out.println("Insufficient balance. Please try again.");
} else {
balance -= amount;
System.out.println("Successfully withdrawn " + amount + ". Your new balance is " + balance);
}
}
public static void deposit() {
System.out.println("Please enter the amount to deposit:");
double amount = input.nextDouble();
balance += amount;
System.out.println("Successfully deposited " + amount + ". Your new balance is " + balance);
}
}
```
这是一个简单的ATM系统,它允许用户检查余额、取款、存款和退出系统。当用户输入选项时,程序执行相应的操作。
阅读全文