// I am new to Java and was practicing some questions on 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 ). When I change it I get error on class 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 源文件)中,您只能拥有一个顶级公共类或接口。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.