Results 1 to 3 of 3
- 03-11-2013, 10:36 PM #1
Member
- Join Date
- Sep 2012
- Posts
- 7
- Rep Power
- 0
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); } }
-
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.
-
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.
Similar Threads
-
No Main Method Found?
By connorlm3 in forum New To JavaReplies: 4Last Post: 02-26-2013, 11:35 PM -
Help me I get this error: Error: Main method not found in class Position
By lo2 in forum New To JavaReplies: 8Last Post: 11-22-2012, 07:16 AM -
main method not found error in class . wat s the error?
By kirankumaragnihotram in forum New To JavaReplies: 10Last Post: 06-29-2012, 11:26 AM -
Main Method not found in class
By HinaKhan in forum New To JavaReplies: 6Last Post: 06-22-2012, 02:34 PM -
main method not found in class
By eLancaster in forum New To JavaReplies: 5Last Post: 02-09-2011, 08:48 AM


1Likes
LinkBack URL
About LinkBacks

Bookmarks