Results 1 to 2 of 2
  1. #1
    eliCanzee is offline Member
    Join Date
    Apr 2009
    Posts
    12
    Rep Power
    0

    Default 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. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    841
    Rep Power
    6

    Default

    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

  1. Calling main method
    By eva in forum New To Java
    Replies: 7
    Last Post: 11-06-2009, 01:37 PM
  2. A query about main method
    By mew in forum New To Java
    Replies: 2
    Last Post: 12-24-2007, 09:44 AM
  3. Private main method
    By bugger in forum New To Java
    Replies: 1
    Last Post: 12-21-2007, 09:45 AM
  4. main method
    By eva in forum New To Java
    Replies: 5
    Last Post: 12-19-2007, 09:25 AM
  5. The main method in java...
    By lenny in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 06:21 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
  •