0

When I create my array field as private double [] balance, I can allocate memory in the constructor class by balance= new double []{n,u,m,b,e,r,s};. However, when I try to allocate memory for a multidimensional array it will not work. The error in netbeans IDE says that I can't convert int into a double. So I'm confused on why this is occurring. Any help would be appreciated. Is this because I'm not including .00 for amounts that are whole (i.e. 12 instead of 12.00)?

Here is my example code:

package myatmexample;


enum AccountType
{
    CHECKINGACCOUNT,
    SAVINGSACCOUNT,
    CDACCOUNT,
};

public class bankUserData
{
private final String []  users;
private AccountType [] userAccounts;
private double [][][] balance;

public bankUserData()
{
    users = new String []
    {
        "Jim Beam", "Bailey Irish-Cream", "Jack Daniels","Grey Goose", "Ginger Skyy", "Marga Rita",
        "Train Wreck", "OG Skywalker", "Flo Green", "Polly Pak", "Princess Diesel","Gracie Slick"
    };

    userAccounts = new AccountType[]
    {
        AccountType.CHECKINGACCOUNT,  
        AccountType.SAVINGSACCOUNT,
        AccountType.CDACCOUNT
    };

    balance = new double [][][]
    {
        { 350, 435, 796, 82.43, 1003.50, 2500, .50, 365, 892, 134, 768, 25892 },
        { 43, 58, 98, 100,54, 33.25, 65.5, 89.7, 71.8, 34.3, 45,67 },
        { 21,23,45,67,68,69,43,21,44,56.78,59, 64 }
    };

    Object [] fullAccountArray = { users, userAccounts };
}
}
Mateusz Grzejek
  • 11,698
  • 3
  • 32
  • 49
MissKP
  • 1

2 Answers2

0
balance= new double [][][]   {{350, 435, 796, 82.43, 1003.50, 2500, .50,  
365, 892, 134, 768, 25892},
{43, 58, 98, 100,54, 33.25, 65.5, 89.7, 71.8, 34.3, 45,67},
{21,23,45,67,68,69,43,21,44,56.78,59, 64}};

The initialisation isn't valid. A 3D-matrix is required, but you only create 2D-matrix within the brackets ({{...}} should be {{{...}}}).

0

You have Array of Arrays of doubles in

{{350, 435, 796, 82.43, 1003.50, 2500, .50, 365, 892, 134, 768, 25892},
{43, 58, 98, 100,54, 33.25, 65.5, 89.7, 71.8, 34.3, 45,67},
{21,23,45,67,68,69,43,21,44,56.78,59, 64}};

When you declared new double [][][]: an Array of Arrays of Arrays of doubles. So in place of 350 it expects an Array of doubles not a double.

Hope it is not confusing ;)

almeynman
  • 7,088
  • 3
  • 23
  • 37