이 코드의 16 행에 오류가 있습니다. 정적에 대한 무언가, 그것을 이해할 수 없다, 어떤 아이디어가 도움이 될 것입니다.정적이 아닌 변수 이것은 정적 컨텍스트 라인에서 참조 할 수 없습니다. 16
package sample1;
import java.util.ArrayList;
import java.util.Date;
public class Sample1 {
//main class
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Account acc1 = new Account("George", 1122, 1000, .015);
System.out.print("The account holder's name: " + acc1.getname()
+ ". The annual interest rate: " + acc1.getrate(.015)
+ ". The balance: " + acc1.getbalance() + ". The monthly interest: "
+ acc1.monthlyInterest + ". All the transactions: "
+ acc1.getTransactions());
}
public class Transaction {
private Date datetrans;
private char type;
private double amount;
private double balance;
private String description;
char Withdraw = 'W';
char deposit = 'D';
public Transaction(Date newDateTrans, char newType, double newAmount,
double newBalance, String newDescription) {
datetrans = newDateTrans;
type = newType;
amount = newAmount;
balance = newBalance;
description = newDescription;
datetrans = new Date();
}
Date getdatetrans() {
return datetrans;
}
char gettype() {
return type;
}
double getamount() {
return amount;
}
String getdescription() {
return description;
}
double getbalance() {
return balance;
}
}
public class Account {
private int id = 0;
private String name;
private double balance = 0;
private double rate = 0;
private Date dateAdded;
private ArrayList<String> transactions = new ArrayList();
public Account(String newName, int newId, double newBalance) // this is where the error is, any ideas why it can be {
id = newId;
name = newName;
balance = newBalance;
dateAdded = new Date();
}
int getid() {
return id;
}
double getbalance() {
return balance;
}
double getrate(double newRate) {
return rate;
}
public void setid(int newId) {
id = newId;
}
public void setbalance(double newBalance) {
balance = newBalance;
}
public void setrate(double newRate) {
rate = newRate;
}
String getname() {
return name;
}
String getTransactions() {
return transactions.toString();
}
Date getDateAdded() {
return dateAdded;
}
double monthlyInterestRate;
double monthlyInterest;
String withdraw;
String deposit;
public double getMonthlyInterestRate() {
monthlyInterestRate = rate/12;
return monthlyInterestRate;
}
public double getMonthlyInterest() {
monthlyInterest = balance * monthlyInterestRate;
return monthlyInterest;
}
String getDeposit() {
return deposit;
}
void addtransactions(String deposit) {
transactions.add(deposit);
}
String getWithdraw() {
return withdraw;
}
void droptransactions(String withdraw) {
transactions.remove(withdraw);
}
}
}
에 당신이 당신의 클래스 선언의 예에 정적 키워드를 넣어야 할이 issuue를 해결합니다. –
실제 필요가 없으면 클래스를 중첩하지 마십시오. 이것이 바로 여기 오류의 원인입니다. –
어떻게해야합니까? – jose