课程: Java Object-Oriented Programming
今天就学习课程吧!
今天就开通帐号,24,600 门业界名师课程任您挑!
Solution: Banking application
(upbeat music) - [Instructor] To add encapsulation to this Java program, the first thing we'll do is make the owner and balance attributes private. Then we'll make these indirectly accessible through public behaviors. In order to create a BankAccount, we need a constructor. With this constructor, we'll input an owner, as well as a startingBalance. For the balance, the user may input an invalid value, such as a negative number. To combat against this, we'll take the max of the startingBalance and zero. This will set the balance to whichever number's higher, either the startingBalance or zero, forcing the balance to be set as a positive number. Now for the setters. We'll make the owner of the BankAccount immutable for now, so no setter is needed. But what about the balance? For the balance, the user should be able to withdraw and deposit money. So instead of creating a setter, we'll create deposit and withdrawal…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。
内容
-
-
-
-
(已锁定)
What is encapsulation?2 分钟 16 秒
-
(已锁定)
Discovering access modifiers2 分钟 35 秒
-
(已锁定)
Implementing encapsulation with access modifiers4 分钟 20 秒
-
(已锁定)
Exploring encapsulation in Java string class3 分钟 37 秒
-
(已锁定)
Challenge: Banking application1 分钟 14 秒
-
(已锁定)
Solution: Banking application4 分钟 29 秒
-
(已锁定)
-
-
-
-