Jump to content

Error: Main method not found in class Account, please define the main method as:


alienA2

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...