Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By Fubarable

Thread: Error: Main method not found! Please help!

  1. #1
    xemkruz2012 is offline Member
    Join Date
    Sep 2012
    Posts
    7
    Rep Power
    0

    Default Error: Main method not found! Please help!

    Main Assignment: Write a class named Rectangle to represent rectangles. The data fields are width, height, and color. Use double for width and height, and String for color. Suppose that all the rectangles are the same color. You need to provide the accessor methods for the properties and a findArea() method for computing the area of the rectangle.
    Write a client program(test class) to test the class Rectangle. In the client program, create two Rectangle objects. Assign any width and height to the two objects. Assign the first object the color red, and the second, yellow. Display the properties of both objects and find their areas.


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



    Java Code:
    public class Rectangle {
    private double width = 1;
    private double height = 1;
    private static String color = "white";
     
                    public Rectangle( ) {
                   
                            }
    
                    public Rectangle ( double widthParam, double heightParam, String colorParam ) { }
    
                    public double getWidth ( ) { 
                    return width;  
                    }  
                    
                    
                    
                    
                    public void setWidth ( double widthParam ) {
                                        if ((width >= 0) || (width <0))
                                                {
                                                    System.out.println("Fatal error");
                                                    System.exit(0);
                                                }
                                        else {
                                              this.width = width;
                                          }
                                      }
    
                    
                    
                    
                    public double getHeight ( ) { 
                                return height;
                                }
                    
                    
    
                    public void setHeight ( double heightParam ) { 
                                    if ((height >= 0) || (height <0))
                                              {
                                                  System.out.println("Fatal error");
                                                  System.exit(0);
                                              }
                                      else {
                                            this.height = height;
                                        }}
    
                    
                    
                    
                    public String getColor ( ) {
                    return color;
                    }
    
                    public void setColor ( String colorParam ) { }
    
                    public double findArea ( ) {
                    double area = width * height;    
                    return area;
                    }
    
        @Override
                    public String toString ( ) { 
                    return ("Deafult height " + height + "Default width " + width + "Default color " + color);
                    }
    
      
    }      
    class Test{
    public static void main(String[] args){
    //invoking no-arg constructor
    Rectangle mr = new Rectangle();
    mr.setHeight(2.0);
    mr.setWidth(3.0);
    double area1 = mr.findArea();
    
    //invoking parameterized constructor
    Rectangle mr2 = new Rectangle(2.0,3.0,"yellow");
    double area2=mr.findArea();
    
    //printing areas
    System.out.println(area1);
    System.out.println(area1);
    }
    
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Error: Main method not found! Please help!

    Is the Test class in its own file called Test.java? If not you should do this, and then compile Test and run Test, not Rectangle.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Error: Main method not found! Please help!

    Cross-posted without warning. Locking thread. Original poster, please let us know when you do this. I know that I personally don't like wasting time answering questions that were answered elsewhere and that I didn't know about since the poster didn't have the decency of informing me.
    DarrylBurke likes this.

Similar Threads

  1. No Main Method Found?
    By connorlm3 in forum New To Java
    Replies: 4
    Last Post: 02-27-2013, 12:35 AM
  2. Replies: 8
    Last Post: 11-22-2012, 08:16 AM
  3. main method not found error in class . wat s the error?
    By kirankumaragnihotram in forum New To Java
    Replies: 10
    Last Post: 06-29-2012, 12:26 PM
  4. Main Method not found in class
    By HinaKhan in forum New To Java
    Replies: 6
    Last Post: 06-22-2012, 03:34 PM
  5. main method not found in class
    By eLancaster in forum New To Java
    Replies: 5
    Last Post: 02-09-2011, 09:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •