i dont know y but my driver wont work. i cant get a= getBalance(). if i create an object like CheckingAccount jjj = new CheckingAccount my scanner wont work. could you hep me fix this problem and also so when i input a negative number it prints out the error from my class.
this is my driver
import java.util.*;
public class CheckingAccountDriver
{
public static void main(String args[])
{
Scanner keyboard = new Scanner(System.in);
System.out.print("Please enter the starting Balance --> ");
double a = keyboard.nextDouble();
a = getBalance();
System.out.println("Account opened with a balance of "+ a);
System.out.print("Please enter the amount of deposit-->");
double b = keyboard.nextDouble();
System.out.println("Deposit made. Current account balance = ");
CheckingAccount lol = new CheckingAccount(a, 0);
}
}
& my Class
public class CheckingAccount
{
private double myBalance;
private int myAccountNumber;
public CheckingAccount()
{
myBalance = 0.0;
myAccountNumber = 0;
}
public CheckingAccount(double initialBalance, int acctNum)
{
if (initialBalance < 0)
throw new IllegalArgumentException("Error: Initial balance cannot be negative");
else
{
myBalance = initialBalance;
myAccountNumber = acctNum;
}
}
public double getBalance()
{
return myBalance;
}
public void deposit(double amount)
{
if (amount < 0)
throw new IllegalArgumentException("Error: amount cannot be negative");
else
myBalance += amount;
}
public void withdraw( double amount )
{
if (amount > myBalance)
throw new IllegalArgumentException("Error: amount cannot be withdrawn");
else
myBalance -= amount;
}
}