mirror of
https://github.com/Dichgrem/Java.git
synced 2026-02-05 04:21:56 -05:00
update:demo9
This commit is contained in:
30
com/study/demo9/Outer.java
Normal file
30
com/study/demo9/Outer.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package com.study.demo9;
|
||||
|
||||
public class Outer {
|
||||
public static void main(String[] args) {
|
||||
Account account = new Account("张三", 1000.0);
|
||||
System.out.println("Can pay 500: " + account.canPay(500));
|
||||
System.out.println("Can pay 1500: " + account.canPay(1500));
|
||||
}
|
||||
}
|
||||
|
||||
class Account {
|
||||
private String ownerName;
|
||||
private double balance;
|
||||
|
||||
public Account(String ownerName, double balance) {
|
||||
this.ownerName = ownerName;
|
||||
this.balance = balance;
|
||||
}
|
||||
|
||||
public boolean canPay(double amount) {
|
||||
SecurityChecker checker = new SecurityChecker();
|
||||
return checker.checkBalance(amount);
|
||||
}
|
||||
|
||||
class SecurityChecker {
|
||||
boolean checkBalance(double amount) {
|
||||
return balance >= amount;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user