Results 1 to 2 of 2
Thread: Help me for main method
- 05-26-2009, 12:11 PM #1
Member
- Join Date
- Apr 2009
- Posts
- 12
- Rep Power
- 0
Help me for main method
Hi I have done the project but I don't know how to add "main" method or better to say I don't know how to create main class for this :
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
/**
Sims the shot of a cannonball. Allows user to input trajectory and velocity.
@author Josh
*/
public class Cannonball
{
/** Names angle of ball. */
private double angle;
/** Gives horizontal distance of ball. */
private double x;
/** Vertical distance of ball */
private double y;
/** Names velocity, or speed cannonball will travel. */
private double velocity;
/** The time that the ball is checked. */
public static final double dT = 0.01;
/** Gravity's effect on the ball. */
public static final double GRAVITY = 9.81;
/** Makes a new ball. */
public Cannonball(double speed, double ang)
{
velocity = speed;
angle = ang * Math.PI / 180;
x = 0;
y = 0;
}
/** Gets speed that ball is moving at. */
public double getSpeed()
{
return velocity;
}
/** Allows user to set velocity. */
public void setSpeed(double vel)
{
velocity = vel;
}
/** Gets angle of ball. */
public double getAngle()
{
return angle;
}
/** Lets user set angle. */
public void setA(double ang)
{
angle = ang;
}
/** Gets length of ball travel. */
public double getX()
{
return x;
}
/** Allows length to be set. */
public void setX(double xVal)
{
x = xVal;
}
/** Gets height of ball travel. */
public double getY()
{
return y;
}
/** Lets setting of y value. */
public void setY(double yVal)
{
y = yVal;
}
}
- 05-26-2009, 12:43 PM #2
Hi
I have highted the main method in green.Please go thru the sunsite for better undestanding the language.As u are in urgency I told u.
Java Code:import javax.swing.*; import java.awt.*; import java.awt.geom.*; /** Sims the shot of a cannonball. Allows user to input trajectory and velocity. @author Josh */ public class Cannonball { /** Names angle of ball. */ private double angle; /** Gives horizontal distance of ball. */ private double x; /** Vertical distance of ball */ private double y; /** Names velocity, or speed cannonball will travel. */ private double velocity; /** The time that the ball is checked. */ public static final double dT = 0.01; /** Gravity's effect on the ball. */ public static final double GRAVITY = 9.81; /** Makes a new ball. */ public Cannonball(double speed, double ang) { velocity = speed; angle = ang * Math.PI / 180; x = 0; y = 0; } /** Gets speed that ball is moving at. */ public double getSpeed() { return velocity; } /** Allows user to set velocity. */ public void setSpeed(double vel) { velocity = vel; } /** Gets angle of ball. */ public double getAngle() { return angle; } /** Lets user set angle. */ public void setA(double ang) { angle = ang; } /** Gets length of ball travel. */ public double getX() { return x; } /** Allows length to be set. */ public void setX(double xVal) { x = xVal; } /** Gets height of ball travel. */ public double getY() { return y; } /** Lets setting of y value. */ public void setY(double yVal) { y = yVal; } [COLOR="SeaGreen"][B]public static void main(String args[]) { Cannonball obj = new Cannonball(); //Call whatever method u want using obj.method name }//main[/B]} }//class [/COLOR]Last edited by RamyaSivakanth; 05-26-2009 at 12:46 PM.
Ramya:cool:
Similar Threads
-
Calling main method
By eva in forum New To JavaReplies: 7Last Post: 11-06-2009, 01:37 PM -
A query about main method
By mew in forum New To JavaReplies: 2Last Post: 12-24-2007, 09:44 AM -
Private main method
By bugger in forum New To JavaReplies: 1Last Post: 12-21-2007, 09:45 AM -
main method
By eva in forum New To JavaReplies: 5Last Post: 12-19-2007, 09:25 AM -
The main method in java...
By lenny in forum New To JavaReplies: 1Last Post: 07-31-2007, 06:21 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks