Cannot resolve Symbol / Invalid method declaration by making a seperate class [closed]

I’m making a little command game project in Java, I’m trying to put my “coinsamount” into “bank” that is in another class. I have a few errors and I’m very confused about it, if anyone could help me out it would be really nice.

Here are the different errors : bank.add(coinsamount); error is “java: non-static method add(int) cannot be referenced from a static context” (from class 1)

Here is the code (class 1 ) :

package Main;
import coins.bank;
import java.util.Random;
import java.util.Scanner;
public class Main {



    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int coinsamount = 0;
        boolean mining;
        boolean playing;
        mining = false;
        playing = true;
        Random coins = new Random();
        System.out.println("Bot successfully started");
        bank Bank = new bank();


        while (playing) {
            String in = input.next();


            if (in.equals("/coins"))
                System.out.println("You have " + coinsamount + " coins!");

            if (in.equals("/mine")) {
                int minedcoins = coins.nextInt(200) + 1;
                coinsamount += minedcoins;
                System.out.println("You've mined " + minedcoins + " coins!");
            }

            if (in.equals("/deposit"))
                bank.add(coinsamount);
            System.out.println("You sucessfully deposited" + coinsamount + "coins");

            if (in.equals("/stop")) {
                break; }


        }
    }
}




And here is the code from class 2 :

package coins;
public class bank {
    public static int amount = 0;

    public int Bank() {
        return amount;
    }

    public void add(int amount) {
        this.amount += amount;
    }
}

Answer

it’s better to name your class with capital letters,

you named the Bank class as bank{} and defined the constructor as Bank(){}, and this is wrong.

changing your code to following will resolve your problem:

class MainClass {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int coinsamount = 0;
        boolean mining;
        boolean playing;
        mining = false;
        playing = true;
        Random coins = new Random();
        System.out.println("Bot successfully started");
        Bank bank = new Bank();


        while (playing) {
            String in = input.next();


            if (in.equals("/coins"))
                System.out.println("You have " + coinsamount + " coins!");

            if (in.equals("/mine")) {
                int minedcoins = coins.nextInt(200) + 1;
                coinsamount += minedcoins;
                System.out.println("You've mined " + minedcoins + " coins!");
            }

            if (in.equals("/deposit"))
                bank.add(coinsamount);

            System.out.println("You sucessfully deposited" + coinsamount + "coins");

            if (in.equals("/stop")) {
                break; 
            }


        }
    }
}

class Bank {
    public static int amount = 0;

    public int Bank() {
        return amount;
    }

    public void add(int amount) {
        this.amount += amount;
    }
}