Complete the following programs to demostrate use of local variables.
Will amount remain same? (Yes or No) and why?
1.
public class CheckingAct
{
private String actNum;
private String nameOnAct;
private int balance;
. . . .
public void processDeposit( int amount )
{
balance = balance + amount ;
}
// modified toString() method
public String toString()
{
return “Account: ” + actNum + “tName: ” + nameOnAct +
“tBalance: ” + amount ;
}
}
2. public class CheckingAct{
private String actNum;
private String nameOnAct;
private int balance;
. . . .
public void processDeposit( int amount ) { // scope of amount starts here balance = balance + amount ; // scope of amount ends here } public void processCheck( int amount ) { // scope of amount starts here
int charge; incrementUse();
if ( balance < 100000 ) charge = 15;
else charge = 0;
balance = balance – amount – charge ; // scope of amount ends here
}
}
