程序无法启动,方法提取/存款



im是方法和类的新手。我编写了一个提取/存款程序,要求提供姓名和余额,允许提取和存款功能。eclipse不允许我运行程序,为什么会这样??我是否要在一个单独的类上创建(public static void main(string[]args)??如果必须的话,什么方法(get/set)留在这个类上或转移到主类?

import java.util.Scanner;
public class bank {
private String name;
private double balance;
private double withdraw;
private double deposit;
private double withdrawTotal;
private double depositTotal;
bank()
{
    name = null;
    balance = 0;        
    withdraw = 0;
    deposit = 0;
    withdrawTotal = 0;
    depositTotal = 0;
}   
public String getname() {
    return name;
}
public double getBalance(){
    return balance;
}
//public double getAnnualInterestRate(){
    //return annualInterestRate;
//}
public double getWithdraw() {
    return withdraw;
}
public double getDeposit() {
    return deposit;
}
public double getWithdrawTotal() {
    return withdrawTotal;
}
public double getDepositTotal() {
    return depositTotal;
}
public void setname(String newname){
    Scanner namescan = new Scanner(System.in);
    name = namescan.nextLine();
}
public void setBalance(double newBalance){
    Scanner bscan = new Scanner(System.in);
    balance = bscan.nextInt();
}

public void setWithdraw(double newWithdraw){
    withdraw = newWithdraw;
}
public void setDeposit(double newDeposit){
    deposit = newDeposit;
}
public void setWithdrawTotal(double newWithdrawTotal){
    deposit = newWithdrawTotal;
}
public void setDepositTotal(double newDepositTotal){
    deposit = newDepositTotal;
}

   //calculate method
public double withdrawCalculuation() {
    return balance - withdraw;
}
public double depositCalculation(){
    return balance + deposit;
}
//public double annualInterestRateCalculation(){
//  return depositTotal * .045;
//}

public void print() {
bank account = new bank();
account.setname(name);
account.setBalance(20000.00);
account.setWithdraw(2500);
account.setWithdrawTotal(17500.00);
account.setDeposit(3000.00);
account.setDepositTotal(20500.00);
//account.setAnnualInterestRate(.045);

System.out.println("The Accound name is:" + account.getname());
System.out.println("The Balance is:" + account.getBalance());
System.out.println("Amount of withdrawal is:" + account.getWithdraw());
System.out.println("The Balance after withdrawal is:" + account.getWithdrawTotal());
System.out.println("Amount of deposit is:" + account.getDeposit());
System.out.println("The Balance after depsoit is:" + account.getDepositTotal());
//System.out.println("The monthly interest for total amount is:" + account.getAnnualInterestRate());
}

}

eclipse不允许我运行程序,为什么会这样

因为JVM无法找到main()方法。

我是否要在一个单独的类上创建(public static void main(string[]args)

没有。您可以在同一个类中添加main()

请从Java基础教程开始。您需要有一个主方法来执行java程序。

相关内容

  • 没有找到相关文章

最新更新