0

Hi, I'm working on a project and I am stuck on the AccountTest.java right at where the program is supposed to process the transaction-code within a while-loop. Below is the pseudocode for that was written for this particular assignment. This is my first post so I hope that I've formated everything correctly. Your help is much appreciated!

Assignment:
Write a Java program to define a class for a simplified bank account and the program to test it.

At the minimum, the Account class will include the following elements

Fields (all Private) (instance variables)

account number
Customer last name, first Name
beginning balance
end balance
total withdrawal
total deposit

Feel free to add extra fields that are needed.

Methods:

Constructor: Will initialize account Number, Last Name, First Name

Usual get and set methods
addDeposit(amount) method: add deposit to the balance
subtractWithdrawa(amount): subtract withdrawal from balance
printStatement: display the values of the fieds listed above. If the balance is negative, will display a message indicating that account is overdrawn.


The test program will read the data for customers and invoke the needed methods. We will assume four Accounts (4 objects declared in the test program). The program will also read transactions (deposits or withdrawals) for the month

Account number: 10000
Customer Last name, First Name: Norbert, Pat
Beginning balance 900
Transactions (must be entered in the order shown) (1 for Deposit, -1 for withdrawal, 0 for end of transaction for current account)
1 250 1 200 -1 150 -1 100 -1 300 0


Account number: 20000
Customer Last name, First Name: Lopez, Andy
Beginning balance 700
Transactions: -1 750 0
Note: this account will be overdrawn

Account number: 30000
Customer Last name, First Name: Pham, Debby
Beginning balance 900
Transactions: -1 50 1 20 -1 150 1 20 0

Account number: 40000
Customer Last name, First Name: Crown, Renee
Beginning balance 300
Transactions: 0 (no transactions)

Input/output:. At your choice: use the class System (MS-DOS window) or a GUI

Pseudocode:
Test Program structure

1. An outer loop (For-Loop). The code inside the outer loop is executed 4 times, once for each account

2. An inner loop (a while-loop nested in the for-loop). This while loop reads the transactions for an account and performs the appropriate processing needed for the account

The following is a skeleton of the code for the test program, you need to fill-in where needed and make sure the syntax works

int transactionCode;
Account acct, acct1, acct2, acct3, acct34;

for (int i =1; ……………)

{ prompt for and read account number, last name, first name;

acct = new Account( 3 arguments here for account number, last name, first name);


Prompt for transaction

Read transactionCode

While (transactionCode. != 0)
{ test transaction code and process transaction
That is compute accrued withdrawals, deposits
Read transaction code
} //end while loop

Compute, set the fields totalDeposit, totalWithdrawals, , endBalance in the
Account object referred to by acct;

Test i (the for-loop control variable) and “saves” the reference to the current
Account object. For example:

If(i==1) acct1 = acct;
…………………..
} //end for-loop

At this point we have 4 Account objects, referred to by acct1, acct2, acct3, acct4

Using the printStatement() method of the class Account, display the information for each account.

Account.java

public class Account
{
	private Integer accountNumber;
	private String customerLastName;
	private String customerFirstName;
	private Integer beginningBalance;
	private Integer endBalance;
	private Integer totalWithdrawal;
	private Integer totalDeposit;

// constructor to initialize account number, last name, and first name
public Account ( Integer actNumber, String last, String first )
{
	accountNumber = acctNumber;
	customerLastName = last;
	customerFirstName = first;
}

// method to set the beginning balance
public void setBeginningBalance( Integer begBalance )
{
	beginningBalance = begBalance;
}
// method to deposit to the account balance
public void addDeposit( Integer depositAmount )
{
	beginningBalance += depositAmount;
	totalDeposit += depositAmount;
}

// method to withdraw from the account balance
public void subtractWithdrawal( Integer withdrawalAmount )
{
	beginningBalance -= withdrawalAmount;
	totalWithdrawal += withdrawalAmount
}

// method to display the account data and display a message
public void printStatement
{
	System.out.println(accountNumber);
	System.out.println(customerFirstName + customerLastName);
	System.out.println();
	If (endBalance < 0)
	{
	System.out.println( "Account is overdrawn." )
	}
	}
	
// indicating that the account is overdrawn



}

AccountTest.java

import java.util.Scanner;

public class AccountTest
{
   public static void main( String[] args ) 
   {
   
   //create Scanner to obtain input from command window
   Scanner input = new Scanner( System.in );
			
     // prompt for and read account number
	  System.out.println( "Please enter your account number:" );
	  Integer accountNumber = input.nextInt();
	  System.out.println( "Please enter your last name:" );
	  String lastName = input.nextLine();
	  System.out.println( "Please enter your first name:" );
	  String firstName = input.nextLine();
	  
// create Account object	  
	  Account acct1 = new Account( 10000, "Norbert", "Pat" );
	  
	  // prompt for transaction
	  System.out.println( "Enter 1 for withdrawal, 2 for deposit, or 3 to view statement." );
	  
	  // read transaction code
	  Integer transactionCode = input.nextInt();
	  
	  
	  
	  
	  
   } // end main
} // end class AccountTest
2
Contributors
1
Reply
9
Views
5 Years
Discussion Span
Last Post by dantinkakkar
0

Hi, I'm working on a project and I am stuck on the AccountTest.java right at where the program is supposed to process the transaction-code within a while-loop. Below is the pseudocode for that was written for this particular assignment. This is my first post so I hope that I've formated everything correctly. Your help is much appreciated!

Can you specifically quote exactly what problem you are facing?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.