2016-08-16 111 views
-4

我得到这个错误缺少main()的错误

Bank类未找到Main方法,请确定的主要方法为: public static void main(String[] args)或JavaFX应用程序类必须扩展javafx.application.Application

这是我的Bank

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; 
    } 
} 
+5

好吧,让您听起来像是在尝试运行“Bank”类......您期望做什么?显示的错误信息对我来说似乎相当清楚。 –

+0

根据他明显缺乏的经验判断,我猜他不知道需要使用Main方法来做任何事情,等等。 – Matt

+2

这是专业人士的Q/A网站,其中您的问题是其他程序员的宝贵资源。这不是一个WhatsApp聊天。请使用“请”,“我”,“不要”等全文,而不是“plz”,“i”,“dnt”,“whr”。 – RealSkeptic

回答

0

Java程序需要有一个主要方法,实质上是程序的起点。我建议通过一些Java教程来开始,因为他们会教你这样的东西。教程点是一个很好的网站。

更改的前几行:

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); 
    } 

(它创建了一个新的银行对象,然后调用该方法)

简单地定义一个类不会做任何事情。这就像处理计算机工具(方法),但不告诉它使用(调用)工具。

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

把这样的东西放在你的课堂上。这是您运行程序时调用的第一种方法