本帖最后由 落尘大大和你呢 于 2021-6-1 12:42 编辑
[Java] 纯文本查看 复制代码 public class Account {
private int ID;
private String name;
private int balance;
public Account() {
}
public int getID() {
return ID;
}
public void setID(int ID) {
this.ID = ID;
System.out.println("账户:" + getID());
}
public Account(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
System.out.println("姓名:" + getName());
}
public int getBalance() {
return balance;
}
public void setBalance(int balance) {
this.balance = balance;
}
public void take(int number1) {
if (balance < number1) {
System.out.print("你的余额不足,取钱失败");
}
if (balance > number1) {
System.out.print("本次操作成功,取出:" + number1 + "元");
//System.out.println("余额:"+ balance - number1);
}
}
public void deposit(int number2) {
balance = number2;
System.out.println("本次操作成功,存入:" + number2 + "元");
System.out.println("余额:" + getBalance());
}
} [Java] 纯文本查看 复制代码 public class CustomerTest {
public static void main(String[] args) {
java.util.Scanner s = new java.util.Scanner(System.in);
System.out.print("请输入您的姓名:");
String name = s.next();
System.out.print("请输入您的账户:");
int account = s.nextInt();
Account e = new Account();
System.out.println("账户信息:");
Account q = new Account();
e.setID(account);
q.setName(name);
Account w = new Account();
System.out.print("请选择本次操作:");
System.out.println("\033[31;4m" + "(1是存款,2是取款)" + "\033[0m");
int r = s.nextInt();
if (r == 1) {
System.out.print("请输入存款数额:");
int deposit = s.nextInt();
w.deposit(deposit);
}
if (r == 2) {
System.out.print("请输入取款数额:");
int take = s.nextInt();
w.take(take);
}
w.getBalance();
}
}
|