# Thread: Help me for main method

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;

}
}

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 01:46 PM.

#### Posting Permissions

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