This site requires JavaScript, please enable it in your browser!
Greenfoot back
divinity
divinity wrote ...

2016/11/14

array required but String found

1
2
divinity divinity

2016/11/14

#
hi danpost, how do i fix this error. have been having this error.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package ATM;
 
import java.text.DecimalFormat;
import java.util.Scanner;
 
 
public class ATM {
    static Account[] acc = new Account[10];
    static Scanner input = new Scanner(System.in);
    static DecimalFormat df = new DecimalFormat("#.00");
     
        public static void main(String[] args)
        {
            createAccount();//create an account
            mainMenu(acc);//the main mean created
        }
        public static void createAccount()
        {
            //instantiates the variables
            int i;
            double bal=50.0;
            Clients[] client = new Clients[10];
             
             
             
            for(i=0; i<acc.length; i++)
            {
                //asking for the user information
                System.out.println("Enter first name");
                String n = input.next();
                System.out.println("Enter address");
                String a = input.next();
                System.out.println("Enter contact");
                String c = input.next();               
                                 
                c[i] = new Clients(n, a, c);//created a new person (this is where I am getting the error, array required but string found
            }
        }
         
        public static void mainMenu(Account[]act)//main menu
        {int test;//asking for the user id
            do
            {
                System.out.println("Enter the ID");//getting id
                test = input.nextInt();
                if(test == -1)
                {
                    System.exit(0);//if user enter the incorrect id the progrm would end
                }
                else
                {
                    //for loop to iterate the array the amount of times the user would enter the their id
                    for(int i=0; i<act.length; i++)
                    {
                        //checking to see if the user enter the correct id
                        if(test==(act[i].getID()))
                        {
                            atmMenu(act[i]);
                            break;
                        }
                    }
                }
            }while(test!=-1);
        }
        public static void atmMenu(Account a)
        {
            double amt; int sel;
            do
            {
                //asking the user to enter the transaction the user wish to make
                System.out.println("Make a selection from the following"//asking the user to make a choice
                        + "\n1\tBalance: "
                        + "\n2\tWithdraw: "
                        + "\n3\tDeposit: "
                        + "\n4\tInformation: "
                        + "\n5\tExit: \n");
                sel = input.nextInt();
                switch(sel)
                {
                    case 1: a.getbalance();//getting acct bal
                             
                        break;
                        //asking the user how much they would like to withdraw
                    case 2: System.out.println("\nHow much would you like to withdraw?\n");//asking for how much to be withdraw
                        amt = input.nextDouble();
                        if(amt>a.getbalance())
                        {
                            //letting the user know the amount they withdraw is not sufficient in the account
                            System.out.println("\nInsufficient funds.\n");//letting the user know there not enough funds
                        }
                        else
                        {
                            a.withdraw(amt);//letting the user know there is enough in the account
                        }
                        break;
                        //asking the user how much the user want to deposit
                    case 3: System.out.println("\nHow much would you like to deposit?\n");//ask how much to be deposited
                        amt = input.nextDouble();
                        a.deposit(amt);//getting the amount to be deposit
                        break;
                         
                    case 4: a.toString();//acquiring the user information
                        break;
                         
                    case 5: break;
                }
            }while(sel!=5);
        }
danpost danpost

2016/11/14

#
Line 36 should begin:
1
client[i]
'c' was your string input; 'client' is your client array.
DJones7 DJones7

2016/11/14

#
Hello danpost i like your work son
divinity divinity

2016/11/14

#
hi danpost i fix that problems and a another one crop in the same place.
1
client[i] = new Client (the error here is clients);
danpost danpost

2016/11/14

#
divinity wrote...
hi danpost i fix that problems and a another one crop in the same place.
1
client[i] = new Client (the error here is clients);
Will need to see the Client class constructor (at least). @DJones7, thanks.
divinity divinity

2016/11/14

#
hi danpost
1
2
3
Clients[] client = new Clients[10]; this is the constructor
 
client[i] = new Client(n, a, c);
Super_Hippo Super_Hippo

2016/11/14

#
That is not the constructor. The constructor is in the Client class and looks like this:
1
2
3
4
public Client(/**some parameters*/)
{
    //....
}
divinity divinity

2016/11/14

#
hi this is what ah hve in the client class
1
2
3
4
public Clients(String n, String a, String c, int cn) {
        super(n, a, c);
        clientNumber = cn;
    }
danpost danpost

2016/11/14

#
divinity wrote...
this is what ah hve in the client class
1
2
3
4
public Clients(String n, String a, String c, int cn) {
        super(n, a, c);
        clientNumber = cn;
    }
From this, then in response to this:
i fix that problems and a another one crop in the same place.
1
client[i] = new Client (the error here is clients);
I would say you are missing the 'int' parameter and it is not 'new Client(...', but 'new Clients(...' (with an 's').
divinity divinity

2016/11/14

#
am still getting an error when i put the s at the end of client
danpost danpost

2016/11/14

#
divinity wrote...
am still getting an error when i put the s at the end of client
You need to supply the error output (at minimum).
divinity divinity

2016/11/14

#
1
c[i] = new Clients(n, a, tn);
danpost danpost

2016/11/14

#
divinity wrote...
1
c[i] = new Clients(n, a, tn);
That may be the line the error occurred on. It is not the error message.
divinity divinity

2016/11/14

#
how could that be. am not seeing it. having rel problem building this program and this constant error one after the next. it is rel frustrating
divinity divinity

2016/11/14

#
in my ide it is saying line 37
There are more replies on the next page.
1
2