0
votes

I try compiling it and it says no error. But when i run the program it says:

Error: Main method not found in class TextBook, please define the main method as: public static void main(String[] args)

so when i add the public static void main, the whole program has so many errors.

import java.util.*;

public class Book

{
private int pageNum;
private String title;
Date today = new Date();

    public Book(int pn, String name)
    {
    pageNum = pn;
    title = name;
    }

    //Setter/Getter for pageNum
    public int getpageNum()
    {
    return pageNum;
    }

    public void setpageNum(int pn)
    {
    pageNum = pn;
    }
    //Setter/Getter for Title
    public String getTitle()
    {
    return title;
    }

    public void setTitle(String name)
    {
    title = name;
    }

    public void display()
    {
    System.out.println("Book.java" + "\nby Tyler " + today);
    System.out.println("Book Title: " + title + "\nNumber of Pages: " + pageNum);
    }
}

for TextBook.java

public class TextBook extends Book
{
private String gradeLevel;

public TextBook(int pageNum, String title, String gl)
    {
    super(pageNum, title);
    gradeLevel = gl;
    }

    //Setter/Getter for gradeLevel
    public String getGradeLevel()
    {
    return gradeLevel;
    }

    public void setGradeLevel(String g)
    {
    gradeLevel = g;
    }

    public void display()
    {
    super.display();
    System.out.println("Grade Level: " + gradeLevel);
    }

}

for DemoBook.java

public class DemoBook
{
    public static void main(String[] args)
    {
    Book oneBook = new Book(250, "Awesome Story");
    TextBook oneTextBook = new TextBook(350, "Awesomer Story", "12");

    oneBook.display();
    oneTextBook.display();
    }
}
3
and btw, this coding is just something i found on the internet. but i used it to run so that i can learn java ! :) - user3132936
try to check your_file.jar in workspace folder, whether it has main method - DRastislav
Would you care to share what those errors were? - Oliver Charlesworth
Error: Main method not found in class TextBook, please define the main method as: public static void main(String[] args) - user3132936
how to check _file.jar? im using JCreator. all i know is how to run the programe. haha - user3132936

3 Answers

0
votes

You can only run java file with main method.

In your case, you can only run DemoBook.java

0
votes

Delete parts - for book.java, for textbook.java for DemoBook.java or mark them as comments and run DemoBook

0
votes
class Maximum_num {
        public void num()
        {
            int x=5;
            int y=6;
            int z=7;
            if(x>y)
            {
                if(x>z)

                {
                    System.out.println("x is maximum number");
                }
            else

                {
                    System.out.println("z is maximum number");
                }
            }
                else if (y>z)
                {
                    System.out.println("z is maximum number");
                }
        }
 }

public  class Calculate
{
    public static void main(String [] args)  
    {
    Maximum_num mn=new Maximum_num();
    mn.num();
    }
}