-4

I'm getting this error

Main method not found in class Bank, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application

Here is my Bank class

public class Bank { //Bank Class to calculate the value for infrastructure of each Bank

    final int N = 9; // Equal to highest number in my CQU Student ID 12029103
    int cost;

    public int costPerBank(int numberOfComputers) {
        // Calculate the total cost for numberOfComputers entered by the user
        if (numberOfComputers == 0) { // When user enters '0' or negative values
            cost=0;
        }
        if (numberOfComputers <= 2 && numberOfComputers >= 1) { // When user enters '1' or '2'
            cost=1000;
        }
        if (numberOfComputers > 2 && numberOfComputers<=20) { // When user enters '3' to '20'
            cost=1000+((numberOfComputers-2)*400);
        }
        if (numberOfComputers > 20 && numberOfComputers<=100) { // When user enters '21' to '100'
            cost=1000+((numberOfComputers-2)*300);
        }
        if (numberOfComputers > 100) { // When user enters more than '100'
            cost=numberOfComputers*200;
        }
    return cost;
    }
}
Alex K.
  • 171,639
  • 30
  • 264
  • 288
  • 5
    Okay, so that sounds like you're trying to run the `Bank` class... what do you expect that to do? The error message shown seems fairly clear to me. – Jon Skeet Aug 16 '16 at 11:47
  • Judging by his apparent lack of experience, I'm guessing he doesn't know that a Main method is needed to do anything, etc. – Matt Aug 16 '16 at 11:50
  • 2
    This is a Q/A site for professionals, where your questions are valuable resources for other programmers. It's not a Whatsapp chat. Please use full words like "Please", "I", "don't" etc., not "plz", "i", "dnt", "whr". – RealSkeptic Aug 16 '16 at 11:50

2 Answers2

0

A Java program needs to have a main method, essentially the starting point of the program. I suggest looking through some Java tutorials to get started, as they'll teach you stuff like this. Tutorialpoints is a good site.

Change the first few lines to:

public class Bank { //Bank Class to calculate the value for infrastructure of each Bank

    final int N = 9; // Equal to highest number in my CQU Student ID 12029103
    int cost;

    public static void main(String[] args) {
        (new Bank()).costPerBank(5);
    }

(It creates a new Bank object, then calls the method on that.)

Simply defining a class won't do anything. It's like handing the computer tools (Methods), but not telling it to use (call) the tools.

Matt
  • 135
  • 1
  • 10
0
public static void main(String[] args){
     Bank bank = new Bank();
     bank.costPerBank(1);
}

Put something like this in your class. This is the first method that is called when you run the program

Young Emil
  • 2,220
  • 2
  • 26
  • 37