Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package richards;
- public class ex33 {
- public static void main(String[] args) {
- BankAccountididntstealfrombook testAcct = new BankAccountididntstealfrombook(1000);
- testAcct.Withdraw(500);
- testAcct.Withdraw(400);
- System.out.println(testAcct.GetBalance());
- System.out.println("expected result: 100");
- //This part below for Ex3.4
- testAcct.addInterest(.10);
- System.out.println("the ammount with interest is " + testAcct.GetBalance());
- }
- }
- ###################################################################################################################################CLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASSCLASS
- package richards;
- public class BankAccountididntstealfrombook {
- private double balance;
- /**
- * constructor for initial balance of balance
- */
- public BankAccountididntstealfrombook(double initialValue){
- balance = initialValue;
- }
- /**
- * deposit some amount into the account
- * @param amount
- */
- public void Deposit(double amount){
- balance = balance + amount;
- }
- /**
- * withdraw some amount from the account
- * @param amount
- */
- public void Withdraw(double amount){
- balance = balance - amount;
- }
- /**
- * get the balance so you can print it or whatever
- * @return
- */
- public double GetBalance(){
- return balance;
- }
- public void addInterest(double rate)
- {
- double newBalance;
- newBalance = balance;
- balance = newBalance + balance * rate;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement