Soy nuevo en Java y todavía estoy tratando de aprender los conceptos básicos, supongo que probablemente cometí un error muy simple. Estoy tratando de crear un código donde dos objetos de la clase SavingsAccount se incrementan en un interés mensual. Aquí está el código que escribí:
class SavingsAccount {
//main
public static void main(String args[]){
savingsAccount saver1 = new savingsAccount(2000.0);
savingsAccount saver2 = new savingsAccount(3000.0);
savingsAccount.modifyAnnualInterestRate(0.04f);
System.out.println("S1: " + saver1);
System.out.println("S2: " + saver2);
savingsAccount.modifyAnnualInterestRate(0.05f);
System.out.println("S1: " + saver1);
System.out.println("S2: " + saver2);
}
//end main
static double annualInterestRate;
private double savingsBalance;
public void savingsAccount(double balance){
savingsBalance = balance;
}
public double calculateMonthlyInterest(){
return (savingsBalance * annualInterestRate)/12;
}
public static void modifyInterestRate(double rate){
annualInterestRate = rate;
}
public double getAnnualInterestRate(){
return annualInterestRate;
}
public double getSavingsBalance(){
return savingsBalance;
}
}
Cuando intento ejecutar el código, se devuelven estos errores:
SavingsAccount.java:29: error: cannot find symbol
savingsAccount saver1 = new savingsAccount(2000.0);
^
symbol: class savingsAccount
location: class SavingsAccount
SavingsAccount.java:29: error: cannot find symbol
savingsAccount saver1 = new savingsAccount(2000.0);
^
symbol: class savingsAccount
location: class SavingsAccount
SavingsAccount.java:30: error: cannot find symbol
savingsAccount saver2 = new savingsAccount(3000.0);
^
symbol: class savingsAccount
location: class SavingsAccount
SavingsAccount.java:30: error: cannot find symbol
savingsAccount saver2 = new savingsAccount(3000.0);
^
symbol: class savingsAccount
location: class SavingsAccount
SavingsAccount.java:31: error: cannot find symbol
savingsAccount.modifyAnnualInterestRate(0.04f);
^
symbol: variable savingsAccount
location: class SavingsAccount
SavingsAccount.java:36: error: cannot find symbol
savingsAccount.modifyAnnualInterestRate(0.05f);
^
symbol: variable savingsAccount
location: class SavingsAccount
6 errors
Si alguien pudiera ayudarme con esto, estaría muy agradecido. ¡Gracias!
No sé lo que está intentando hacer, pero aquí está su código compilable
class SavingsAccount {
//main
public static void main(String args[]){
SavingsAccount saver1 = new SavingsAccount();
SavingsAccount saver2 = new SavingsAccount();
saver1.savingsAccount(2000.0);
saver2.savingsAccount(3000.0);
SavingsAccount.modifyInterestRate(0.04);
System.out.println("S1: " + saver1.calculateMonthlyInterest());
System.out.println("S2: " + saver2.calculateMonthlyInterest());
SavingsAccount.modifyInterestRate(0.05);
System.out.println("S1: " + saver1.calculateMonthlyInterest());
System.out.println("S2: " + saver2.calculateMonthlyInterest());
}
//end main
static double annualInterestRate;
private double savingsBalance;
public void savingsAccount(double balance){
savingsBalance = balance;
}
public double calculateMonthlyInterest(){
return (savingsBalance * annualInterestRate)/12;
}
public static void modifyInterestRate(double rate){
annualInterestRate = rate;
}
public double getAnnualInterestRate(){
return annualInterestRate;
}
public double getSavingsBalance(){
return savingsBalance;
}
}
Este artículo se recopila de Internet, indique la fuente cuando se vuelva a imprimir.
En caso de infracción, por favor [email protected] Eliminar
Déjame decir algunas palabras