Home>

Please write your question in detail here.
(Example) I am making a ●● system with PHP (CakePHP).
■■ The following error message occurred while implementing the function.

Error: No suitable method found for put (String)
            customer.put (name);
                    ^ ^
    Method Map.put (String, Account) is not available
      (The length of the actual argument list and the formal argument list are different)
    Method Dictionary.put (String, Account) cannot be used
      (The length of the actual argument list and the formal argument list are different)
    Method Hashtable.put (String, Account) is not available
      (The length of the actual argument list and the formal argument list are different)
import java.util.Hashtable;
public class Bank {
    private Hashtablecustomer;/* Account list * /
    private int balance;
    public Bank () {/ * Initialize account list * /
        customer = new Hashtable();
    }
    public int open (String name/* account name * /) {
        int i = 1;
        if (customer.get (name)! = null) {
            return -7;
        } else {
            customer.put (name);
            balance = 0;
            i ++;
            return 0;
        }
public int close (String name/* account name * /) {
        if (customer.get (name) == null) {
            return -7;
        } else if (balance! = 0) {
            return -1;
        } else {
            customer.remove (name);
            return 0;
        }
    }/* Account cancellation * /
    public int deposit (String name/* account name * /, int amount/* deposit amount * /) {
        if (customer.get (name) == null) {
            return -7;
        } else if (amount<= 0) {
            return -3;
        }
        balance = balance + amount;
        return 0;
    } /* deposit */
public int withdraw (String name/* account name * /, int amount/* withdrawal amount * /) {
        if (customer.get (name) == null) {
            return -7;
        } else if (amount<= 0) {
            return -3;
        } else if (balance
What I tried

I'm a beginner and want to know the solution tomorrow
Please help TT
ATM program

Supplementary information (FW/tool version, etc.)

Please provide more detailed information here.

  • Answer # 1

    As per the error message. The method you are trying to use does not match the number of its arguments.
    The HashTable # put method requires two arguments, a key argument and a corresponding value argument.
    Even if only the key is passed, an error will occur because you do not know what to associate with.

    In the first place, it is recommended to use Map such as HashMap instead of HashTable when developing a new one.

    This class is now a member of the Java Collections Framework as a result of improvements to implement the Map interface as of Java 2 Platform v1.2. Unlike the new collection implementation, Hashtable is synchronized. If you don't need a thread-safe implementation, we recommend that you use HashMap instead of Hashtable. If you need a thread-safe and highly parallel implementation, we recommend that you use ConcurrentHashMap instead of Hashtable.

  • Answer # 2

    I declared private Myname and put it in the value in put to solve it!

  • Answer # 3

    I did private String Myname;to customer.put (name, Myname);and it worked!