【问题标题】:program cant start, methods withdraw / deposit程序无法启动,方法提款/存款
【发布时间】:2013-12-23 12:20:47
【问题描述】:

我对方法和类很陌生。 我编写了一个提款/存款程序,它要求提供姓名和余额,允许提款和存款功能。 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());
}



}

【问题讨论】:

    标签: java class methods main


    【解决方案1】:

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

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

    我想在一个单独的类上创建 (public static void main (string[] args) 吗??

    没有。您可以在同一个班级添加您的main()

    【讨论】:

      【解决方案2】:

      请从 Basic Java tutorial 开始。你需要有一个 main 方法来执行一个 java 程序。

      【讨论】:

        猜你喜欢
        • 2019-01-29
        • 2023-03-26
        • 2019-11-04
        • 1970-01-01
        • 2013-06-10
        • 2020-04-07
        • 2022-01-02
        • 2016-12-29
        • 1970-01-01
        相关资源
        最近更新 更多