alienA2 19 Posted March 30, 2012 Report Share Posted March 30, 2012 I got this code that will not run. I took the code from a book for dummies. I understand what it is asking but I do not know why since the book shows this code as if it should work when it runs. Please advice. error:C:\java_prog\mywork\Account>java AccountError: Main method not found in class Account, please define the main method as: public static void main(String[] args) code: import java.text.NumberFormat;import static java.lang.System.out;class Account{ // variable declarations String naam; int dompas; double jousakie; void display() { NumberFormat moola = NumberFormat.getCurrencyInstance(); out.print("The account with last name "); out.print(naam); out.print(" and ID number "); out.print(dompas); out.print(" has balance "); out.println(moola.format(jousakie)); }} Quote Link to post Share on other sites
smiles 7 Posted March 30, 2012 Report Share Posted March 30, 2012 (edited) java command needs main() function to run import java.text.NumberFormat;import static java.lang.System.out; class Account {// variable declarationsString name;int dompas;double jousakie; /* Constructor here */Account(String n, int d, double j){this.name = n;this.dompas = d;this.jousakie = j;} static void display() {NumberFormat moola = NumberFormat.getCurrencyInstance();out.print("The account with last name ");out.print(name);out.print(" and ID number ");out.print(dompas);out.print(" has balance ");out.println(moola.format(jousakie));} public static void main(String[] args){// you need constructor or will get ClassNotFound exceptionAccount acc = new Account("test", 1, 5000);acc.display(); } } Edited March 30, 2012 by smiles Quote Link to post Share on other sites
smiles 7 Posted March 30, 2012 Report Share Posted March 30, 2012 uhm ..., seems that I was wrong, pls remove static from void display() just void display() Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.