Method to Process Checks

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page

Answer:

class CheckingAccount
{
  // instance variables
  String accountNumber;
  String accountHolder;
  int    balance;

  //constructors
  . . . .

  // methods
  . . . .

  void processDeposit ( int amount )
  {

    balance = balance + amount ;
  }

}

Method to Process Checks

If you have the previous test program in a file, it would be nice to add the processDeposit() method and test it. The method to process a check is slightly more complicated:

  • Assume that the amount of a check is a positive value, expressed in cents.
  • If the current balance is less than $1000.00, there is a $0.15 processing charge.
  • The amount of the check and the processing charge (if any) are subtracted from the balance.
  • The return type is void.

Here is a sketch of the method:

void processCheck( int  )
{
  int charge;
  if (  < 100000 )

    charge =  ;
  else

    charge =  ;

  balance =  -  -  ;

}

QUESTION 15:

Fill in the blanks to complete the method.