Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I ' m trying to output a certain number ( 7 0 0 0 ) , but it keeps returning the same number I put

I'm trying to output a certain number (7000), but it keeps returning the same number I put in. Am I missing something or did I not type something correctly? This is the code so far:
class UML_Lab_Driver {
public static void main(String[] args){
Person Bob = new Person("Bob");
Bob.deposit(9000);
Bob.withdraw(4000);
Bob.deposit(2000);
System.out.println(Bob.getAccountBalance());//expecting 7000
}
}
class Person{
private Account account;
private String name;
private int value;
public Person(String name){
this.name=name;
}
public String getName(){
return name;
}
public void deposit(int amt){
account = new Account(amt);
}
public void withdraw(int amt){
account = new Account(amt);
}
public int getAccountBalance(){
return value=account.getValue();
}
}
class Account{
private int value;
public Account(int value){
this.value=value;
}
public Account (Account p){
value=p.value;
}
public int withdraw(int amt){
value -= amt;
if(value <0){
System.out.println("EXCESS WITHDRAW ALERT.
You will only withdraw the amount equal to what was left in your account.");
value=0;
}
return value;
}
public int deposit(int amt){
value += amt;
return value;
}
public int getValue(){
return value;
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Online Market Research Cost Effective Searching Of The Internet And Online Databases

Authors: John F. Lescher

1st Edition

0201489295, 978-0201489293

More Books

Students also viewed these Databases questions