In the following code have used the main method to print the account number and updated balance after every transaction, or until a Q is entered.
In the methodUpdate balance which, given the balance of the account, the type of transaction( D = deposit, W = withdrawl, Q = quit) and the amount for the transaction, computers and returns the new account balance after depositing or withdrawing the given amount number.
However now I have ran into problems and not sure how to fix this code I have produced
import java.util.Scanner ;
public class CustomerAccount
{
public static void main( String[] args )
{
Scanner in = new Scanner(System.in);
System.out.print("Please enter the account number: ") ;
String accountNumber = in.nextLine() ;
System.out.print("Please enter the initial balance: ") ;
int startingBal = in.nextInt() ;
int updatedBal = startingBal ;
System.out.print("Please enter the transaction type /(D to deposit, W to withdraw, Q to quit: ") ;
String type = in.nextLine() ;
while(!"Q".equals(type))
{
System.out.print("Please enter the amount to be deposited or withdrawn: ") ;
int adjustment = in.nextInt();
if(type.equals("D"))
{
updatedBal = updatedBalance(depositAmt);
}
else
updatedBal = updatedBalance(withdrawAmt);
}
System.out.println("Account Number: " + accountNumber + " UpdatedBalance: $" + updatedBal) ;
}
}
public static int updatedBalance(int amount)
{
amount = amount + adjustment ;
return amount;
}
}
gives the follwoing output:
[File: /CustomerAccount.java Line: 28, Column: 19] class, interface, or enum expected
[File: /CustomerAccount.java Line: 31, Column: 9] class, interface, or enum expected
[File: /CustomerAccount.java Line: 32, Column: 5] class, interface, or enum expected