Powered by Invision Power Board

 
    Reply to this topicStart new topicStart Poll

> Simple Java Math Question
Unspecified
Golem
Posted: Feb 3 2007, 11:59 PM
Quote Post


Really short legs
[*][*][*]

Group Icon
Group: Members
Posts: 930
Member No.: 1603
Joined: 4-November 05

Status: (0d) [--]


I've been having trouble understanding what to do in my Java class (pun totally intended), as my teacher has been assigning lots of programming homework but has very seldom worked with us in class periods to program things.

Whining aside, if anyone knows Java, I'd appreciate some help here:

This is the Cube.java/Cube.class file:

CODE
public class Cube
{ private int side; //instance variables
public Cube(int s){} //constructor
public int getArea() //instance method
{ return side * side * 6;
}
public int getVolume() //instance method
{ return side * side * side;
}
}


And this is the CubeUser.java/CubeUser.class file:

CODE
public class CubeUser
{
public void main(int argv[])
{ Cube cube1 = new Cube(5);
 Cube cube2 = new Cube(6);
 Cube cube3 = new Cube(7);
 cube1.getArea();
 cube1.getVolume();
 cube2.getArea();
 cube2.getVolume();
 cube3.getArea();
 cube3.getVolume();
}
}


I get this error:
java.lang.NoSuchMethodError: main
Exception in thread "main"
And I have no clue how to fix it. Am I not defining what the main method is? If I'm not, how would I go around doing that?
I am a beginner in Java, just trying to get a feel for how things work, so I realize this may be a stupid question for some of you. Any help is appreciated!


--------------------
Quoth the raven, "~teehee~"
PMEmail PosterUsers WebsiteAOL
Top
Unspecified
Quicky
Posted: Feb 4 2007, 12:05 AM
Quote Post


a weed in glaber's garden
[*]

Group Icon
Group: Members
Posts: 12957
Member No.: 7
Joined: 13-October 03

Status: (0d) [--]


you may need to have main methods in both classes


--------------------
the only good userbar on earth:

PM
Top
Unspecified
Golem
Posted: Feb 4 2007, 07:18 PM
Quote Post


Really short legs
[*][*][*]

Group Icon
Group: Members
Posts: 930
Member No.: 1603
Joined: 4-November 05

Status: (0d) [--]


Hmm, tried that but I got the same error. Thanks anyway.

If anyone else has any ideas, please post them, otherwise I'll just ask my teacher.


--------------------
Quoth the raven, "~teehee~"
PMEmail PosterUsers WebsiteAOL
Top
United States
Techokami
Posted: Feb 5 2007, 12:39 PM
Quote Post


Quit Stalin!
[A][S][*][*][*]
[*]

Group Icon
Group: MFGG Security Ninja
Posts: 7507
Member No.: 30
Joined: 13-October 03

Status: (0d) [--]


Sweet monkey Tuesdays, your code is friggin' terse.

I can probably help you, but you need to add in some new lines and indentation first so I can READ it :X


--------------------
user posted image
user posted image user posted image user posted image user posted image user posted image
PMUsers WebsiteIntegrity Messenger IMICQAOLYahooMSN
Top
United States
Techokami
Posted: Feb 6 2007, 08:14 PM
Quote Post


Quit Stalin!
[A][S][*][*][*]
[*]

Group Icon
Group: MFGG Security Ninja
Posts: 7507
Member No.: 30
Joined: 13-October 03

Status: (0d) [--]


Okay, I think I see the problem now. In CubeUser.java, at line 3, replace with:
CODE
public static void main(String[] args)

You were thinking in C =P


--------------------
user posted image
user posted image user posted image user posted image user posted image user posted image
PMUsers WebsiteIntegrity Messenger IMICQAOLYahooMSN
Top
Unspecified
Golem
Posted: Feb 6 2007, 08:17 PM
Quote Post


Really short legs
[*][*][*]

Group Icon
Group: Members
Posts: 930
Member No.: 1603
Joined: 4-November 05

Status: (0d) [--]


QUOTE (Techokami @ Feb 6 2007, 09:14 PM)
You were thinking in C =P

If you say so. I have no knowledge of C whatsoever. biggrin.gif

Anyhow, thanks, it's working now.


--------------------
Quoth the raven, "~teehee~"
PMEmail PosterUsers WebsiteAOL
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

  Topic Options Topic Options Reply to this topicStart new topicStart Poll

 




[ Script Execution time: 0.0698 ]   [ 14 queries used ]   [ GZIP Enabled ]   [ Server Load: 1.82 ]