alienA2 Posted March 30, 2012 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)); }} Link to comment Share on other sites More sharing options...
smiles Posted March 30, 2012 Share Posted March 30, 2012 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(); } } Link to comment Share on other sites More sharing options...
smiles Posted March 30, 2012 Share Posted March 30, 2012 uhm ..., seems that I was wrong, pls remove static from void display() just void display() Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.