Hi, I'm reading this book about Java right now and in it was this example so I wrote it off and tested it...
I get the error "Exception in thread "main" java.lang.NoSuchMethodError: main" and from what I've understood it's because I am missing a main class... Here's the deal though:
1) Have I missed something or is this just an incomplete part or why didn't the author include any main class?
2) As a newbie to this, I feel very confused since several other of his examples are like this. What would the best thing to do in this situation? Should I not continue to write these, what would be the best to fix this etc...?
public class Bankaccount {
private int accntNbr; //kontonummer
private int balance; //saldo
/** skapar ett bankkonto med numret accntNbr och saldot noll */
public Bankaccount (int accntNbr) {
this.accntNbr = accntNbr;
this.balance = 0;
}
/** Tar reda på kontonummret */
public int getAccntNbr() {
return accntNbr;
}
/** saldo */
public int getBalance (){
return balance;
}
/** Sätter in amount kronor på konto */
public void deposit(int amount){
balance = balance + amount;
}
/** tar ut amount från kontot */
public void withdraw (int amount) {
if (amount <=balance){
balance = balance - amount;
} else {
System.out.println("Du försökte ta ut" + amount);
System.out.println("men du har bara" + balance);
System.out.println("på ditt konto");
}
}
}