The code is working just fine so far but it needs to add up the totals from both accounts and I can't figure it out for the life of me. Here is my codes
Driver
/********************************************************************
* LuisSilvaProg4.java
* Luis Silva
*
* This is the driver program that outputs objects from the
* SavingsAccount.java class
*********************************************************************/
public class LuisSilvaProg4 {
public static void main( String args[] ){
//Recalling information from both objects Saver1 and saver2
SavingsAccount saver1 = new SavingsAccount(10002, 2000.00);
SavingsAccount saver2 = new SavingsAccount(10003, 3000.00);
SavingsAccount.newInterestRate( 0.05 );
System.out.println( "\nMonthly balances for one year with 0.05 annual interest:\n" );
//Table heading
System.out.printf( "%10s%10s%10s%10s%10s\n", "Month", "Account#", "Balance", "Account#", "Balance" );
System.out.printf( "%10s%10s%10s%10s%10s\n", "-----", "--------", "-------", "--------", "-------" );
System.out.printf( "%10s%10s%10s%10s%10s\n", "0",saver1.getACCOUNT_NUMBER(), saver1.toString(),
saver2.getACCOUNT_NUMBER(), saver2.toString());
//for loop to output a year long interest increments
for ( int month = 1; month <= 12; month++ ){
switch (month){
case 1:System.out.printf( "\n");
break;
case 2:System.out.printf( "\n");
break;
case 3:System.out.printf( "\n");
break;
case 4:System.out.printf( "\n");
break;
case 5:System.out.printf( "\n");
break;
case 6:System.out.printf( "\n");
break;
case 7:System.out.printf( "\n");
break;
case 8:System.out.printf( "\n");
break;
case 9:System.out.printf( "\n");
break;
case 10:System.out.printf( "\n");
break;
case 11:System.out.printf( "\n");
break;
case 12:System.out.printf( "\n");
break;
}//end switch
//This outputs the incremented amounts monthly
String monthLabel = String.format( "%d", month );
saver1.addMonthlyInterest(); saver2.addMonthlyInterest();
System.out.printf( "%10s%10s%10s%10s%10s\n", monthLabel,
saver1.getACCOUNT_NUMBER(), saver1.toString(), saver2.getACCOUNT_NUMBER(),
saver2.toString());
}//end for
// After the last month’s printout, compute and display the total of both balances.
System.out.printf( "%10s%10s\n", "\nFinal balance of both accounts combined:", "######");
}//end main
}//LuisSilvaProg4
And here is my class program
/**************************************************************
* SavingsAccount.java
* Luis Silva
*
* Class file to calculate 5 percent interest in a bank accnt
**************************************************************/
public class SavingsAccount {
private static double annualInterestRate = 0;
int ACCOUNT_NUMBER; // instance constant
double Balance = 0.0; // instance variable
//This sets the interest rate to 5%
public static void newInterestRate( double interestRate ){
annualInterestRate = .05;
}//end newInterestRate
//Two-parameter constructor for instance constant & instance variable
public SavingsAccount(int account, double balance) {
this.ACCOUNT_NUMBER = account;
this.Balance = balance;
}//end constructor
//Accessors for the instance constant and instance variables
public int getACCOUNT_NUMBER(){
return ACCOUNT_NUMBER;
}//end accessor1
public double getBalance(){
return Balance;
}//end accessor 2
//formula for the monthly interest rate
public void addMonthlyInterest () {
Balance += (Balance * annualInterestRate / 12);
}//end addMonthlyInterest
//This method makes the format to be printed
public String toString(){
return String.format( "$%.2f", Balance );
}//end toString
}//end class
Thanks fellas or gals

New Topic/Question
Reply



MultiQuote






|