简体   繁体   English

Netbeans 编译错误

[英]Netbeans compilation error

// I am new to Java and was practicing some questions on netbeans. // 我是 Java 新手,正在练习有关 netbeans 的一些问题。 I get compilation error on public class bank_acc ( ide is suggesting me to change the name of my whole program to bank_acc but as far as I know the program name is same as the class name which has the main function ).我在公共类 bank_acc 上遇到编译错误(ide 建议我将整个程序的名称更改为 bank_acc,但据我所知,程序名称与具有主要功能的类名称相同)。 When I change it I get error on class prog2.当我更改它时,我在类 prog2 上出现错误。 Either way it's not working out.无论哪种方式都行不通。 Please help.请帮忙。

package prog2;
import java.util.Scanner;

public class bank_acc{
    String name;
    double acc_no;
    String acc_type;
    double bal;
    Scanner s = new Scanner(System.in);

    void bank_acc(){
        System.out.println("Enter basic values");
        name = s.nextLine();
        acc_no = s.nextInt();
        acc_type = s.nextLine();
        bal = 1000;
    }
    // function to deposit money in acc.
    void deposit(){
        System.out.println("Enter the amount to be deposited");
        double amt=s.nextDouble();
        bal+=amt;
    }
    // function to withdraw amt after checking it.
    void wac(){ 
        System.out.println("Current balance = "+bal);
        System.out.println("Enter amount to be withdrawn");
        Double wdraw_amt=s.nextDouble();
        bal-=wdraw_amt;
    }
    void display(){
        System.out.println("Welcome to THE BANK !");
        System.out.println("Your name is: "+name);
        System.out.println("Account Balance: "+bal);
    }

}
public class Prog2{


    public static void main(String[] args) {
        // TODO code application logic here
        bank_acc a = new bank_acc();
        a.deposit();
        a.wac();
        a.display();
        System.out.println("Thank you. Keep working!");

    }

}

在任何 Java 编译单元(.java 源文件)中,您只能拥有一个顶级公共类或接口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM