我有2个Java文件。一个人创建用于保存帐户的类。另一个应该测试它。不幸的是,我收到错误“无法找到或加载主类”。
包zad6;
公共类SavingsAccount { private double annualInterestRate,balance,accumulativeInterest,accumulativeDeposits = 0,accumulativeWithdrawals = 0;
// Constructor
public SavingsAccount(double b)
{
balance = b;
}
// Mutators
public void withdraw(double w)
{
balance -= w;
accumulativeWithdrawals += w;
}
public void deposit(double d)
{
balance += d;
accumulativeDeposits += d;
}
public void addMonthlyInterest()
{
accumulativeInterest += balance * (annualInterestRate/12);
balance += balance * (annualInterestRate/12);
}
// Setters
public void setBalance(double b)
{
balance = b;
}
public void setAnnualInterestRate(double air)
{
annualInterestRate = air;
}
// Getters
public double getBalance()
{
return balance;
}
public double getAnnualInterestRate()
{
return annualInterestRate;
}
public double getMonthlyInterest()
{
return balance * (annualInterestRate/12);
}
public double getAccumulativeInterest()
{
return accumulativeInterest;
}
public double getAccumulativeDeposits()
{
return accumulativeDeposits;
}
public double getAccumulativeWithdrawals()
{
return accumulativeWithdrawals;
}
}
和班级考试:
import java.util.Scanner;
public class SavingsAccountTest {
public static void main(String[] args)
{
int monthsPassed;
Scanner userInput = new Scanner(System.in);
System.out.print("Please enter the starting balance: $");
SavingsAccount demoAccount = new SavingsAccount(userInput.nextDouble());
System.out.print("Enter the annual interest rate (decimal): ");
demoAccount.setAnnualInterestRate(userInput.nextDouble());
System.out.print("Enter the number of months that have passed since the account\'s establishment: ");
monthsPassed = userInput.nextInt();
for (int count = 1; count <= monthsPassed; count++)
{
System.out.println("\n-----MONTH " + count + "-----");
System.out.printf("Enter the amount deposited into the account: $");
demoAccount.deposit(userInput.nextDouble());
System.out.printf("Enter the amount withdrawn from the account: $");
demoAccount.withdraw(userInput.nextDouble());
System.out.printf("This month\'s interest is: $%.2f\n", demoAccount.getMonthlyInterest());
demoAccount.addMonthlyInterest();
}
System.out.printf("\nEnding balance: $%.2f", demoAccount.getBalance());
System.out.printf("\nTotal deposits: $%.2f", demoAccount.getAccumulativeDeposits());
System.out.printf("\nTotal withdrawals: $%.2f", demoAccount.getAccumulativeWithdrawals());
System.out.printf("\nTotal interest: $%.2f", demoAccount.getAccumulativeInterest());
userInput.close();
}
}
错误在哪里?