So, this is my class which contains my constructor and accessor methods:
public class sac
{
// Initializing instance variables.
private double bal;
private double[] dep;
private double[] wit;
/**
* Constructor for objects of class sac
*/
public sac()
{
//Declaring instance variables
bal = 500;
//Deposits:
double[] dep = new double[5];
dep[0] = 100.00;
dep[1] = 124.00;
dep[2] = 78.92;
dep[3] = 37.55;
dep[4] = 83.47;
//Withdrawals:
double[] wit = new double[7];
wit[0] = 29.88;
wit[1] = 110.00;
wit[2] = 27.52;
wit[3] = 50.00;
wit[4] = 12.90;
wit[5] = 15.20;
wit[6] = 11.09;
}
/**
* Returns and sets the value of balance.
*
*
* @return bal
*/
public double setBal(double b)
{
//Declaring instance variables
b = bal;
return bal;
}
/**
* Returns and sets the values of deposits.
*
*
* @return deposits
*/
public double[] getDep()
{
double[] d = new double[5];
//Deposits:
d[0] = dep[0];
d[1] = dep[1];
d[2] = dep[2];
d[3] = dep[3];
d[4] = dep[4];
return d;
}
/**
* Returns and sets the values of withdrawals.
*
*
* @return withdrawals
*/
public double[] getWit()
{
double[] w = new double[7];
//Withdrawals:
w[0] = wit[0];
w[1] = wit[1];
w[2] = wit[2];
w[3] = wit[3];
w[4] = wit[4];
w[5] = wit[5];
w[6] = wit[6];
return w;
}
}
The code may be sloppy as I have been messing around trying to find out the solution to this error, however this is my driver which I am trying to run. The error occurs while trying to call my values from my accessor methods in the other class.
import java.util.*;
/**
*/
public class sacDemo
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in); //Creates new scanner object.
sac sac = new sac(); //Creates accessor object to retrieve variables from sac class.
int bal;
double air;
double[] dep = new double[5];;
double[] wit = new double[7];
double[] d = dep;
double[] w = wit;
w = sac.getWit();
d = sac.getDep();
System.out.println("What is your annual interest rate?");
air = input.nextInt();
air = air/10;
System.out.println("Your deposits for the month were: ");
for(int i=0;i<5;i++){
System.out.println(dep[i]);
}
System.out.println("Your withdrawals for the month were: ");
for(int i=0;i<6;i++){
System.out.println(wit[i]);
}
}
}