Modify class Account (attached in Blackboard) to provide
• An integer class instant variable accountNum to be the class number
(Don’t forget that you need to change the constructor).
• A method called debit that withdraws money from an Account. Ensure that
the debit amount does not exceed the Account’s balance. If it does, the
balance should be left unchanged and the method should print a message
indicating “Debit amount exceeded account balance.”
• In method getBalance(), add a line to print out the account number and
account balance, then in the Test program, you just need to type,
account1.getBalance(); instead of the printf statement.
AccountTest file has been modified already to test your new Accountclass, so you
do not need to change it.
here is my code for the Account Class
public class Account
{
private double balance;
public int accountNum;
public int Account;
public Account(double initialBalance, int accountN)
{
if ( initialBalance > 0.0 )
balance = initialBalance;
accountNum=accountN;
}
public void credit( double amount )
{
balance = balance + amount;
}
public void debit(double amount)
{
if (amount>=balance)
System.out.println("Debit amount exceeded account balance.");
else
balance-=amount;
}
public String getBalance()
{
return balance+" "+accountNum;
}
}
Here is the Code For The AccountTest class
import java.util.Scanner;
public class AccountTest
{
// main method begins execution of Java application
public static void main( String args[] )
{
Account account1 = new Account( 1, 50.00 ); // create Account object
Account account2 = new Account( 2, -7.53 ); // create Account object
// display initial balance of each object
account1.getBalance();
account2.getBalance();
// create Scanner to obtain input from command window
Scanner input = new Scanner( System.in );
double depositAmount; // deposit amount read from user
System.out.print( "Enter deposit amount for account2: " );
depositAmount = input.nextDouble(); // obtain user input
System.out.printf( "\nadding %.2f from account1 balance\n", depositAmount );
account2.credit( depositAmount ); // add amount to account1
// display balances
account1.getBalance();
account2.getBalance();
// create Scanner to obtain input from command window
input = new Scanner( System.in );
double withdrawalAmount; // withdrawal amount read from user
System.out.print( "Enter withdrawal amount for account1: " );
withdrawalAmount = input.nextDouble(); // obtain user input
System.out.printf( "\nsubtracting %.2f from account2 balance\n", withdrawalAmount );
account1.debit( withdrawalAmount ); // subtract amount from account2
// display balances
account1.getBalance();
account2.getBalance();
} // end main
} // end class AccountTest
i cannot figure out what is missing please help thanks a bunch.
You just have your Account constructor to accept a double and an int, in that order.
So right after your main method you have
When it should be
All methods and constructors in java will only work if you pass values exactly as they are in the method declaration. Generally every time you see a “cannot find symbol” error it’s this problem.