5 Replies - 1460 Views - Last Post: 14 November 2009 - 10:49 AM Rate Topic: -----

#1 gibson.nathan   User is offline

  • D.I.C Regular
  • member icon

Reputation: 8
  • View blog
  • Posts: 294
  • Joined: 06-October 09

variable and methods

Posted 13 November 2009 - 04:55 PM

im writing this and i am trying to compile, but i cant find why this wont work.
/**
 * Write a description of class Catapult here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Catapult
{
	public double launchSpeed;
	public double launchAngle;
	public double distance;
	public static final double accelerationDueToGravity = 9.8;
	public static final double speedFeetFactor = 3.28;
	public double distanceFeet;
	
	
	

	public Catapult(double speed, double angle)
	{
		angle = launchAngle;
		speed = launchSpeed;
		
	}
	
	public double distanceMeters()
	{
		
		distance = speed * speed * Math.sin(2 * angle) / accelerationDueToGravity;
		return distance;
	}
	
	public double distanceFeet()
	{
		distanceFeet = distance * speedFeetFactor;
		return distanceFeet;
	}
}


it says that it cannot find variable speed.

Is This A Good Question/Topic? 0
  • +

Replies To: variable and methods

#2 gawdlike   User is offline

  • you can't fix stupid.

Reputation: -7
  • View blog
  • Posts: 647
  • Joined: 16-November 08

Re: variable and methods

Posted 13 November 2009 - 05:01 PM

That means the variable isn't declared anywhere in the program.

What is the program supposed to do? Where does it get speed etc?
Was This Post Helpful? 0
  • +
  • -

#3 gibson.nathan   User is offline

  • D.I.C Regular
  • member icon

Reputation: 8
  • View blog
  • Posts: 294
  • Joined: 06-October 09

Re: variable and methods

Posted 13 November 2009 - 05:03 PM

i have another class like so:

/**
 * Write a description of class CatapultTester here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
import java.util.ArrayList;
public class CatapultTester
{
	public static void main(String[] args)
	   {
		   ArrayList<Integer> intList = new ArrayList<Integer>();
			
		   for(int i = 0; i < angle.length; i ++)						  
		   {			 
				intList.add(angle);  
				intList.ass(speed);
		   }
			
			
			
			//print header
			System.out.println("												 Projectile Distance (feet)");
			System.out.println("  MPH \t 25 deg \t 30 deg \t 35 deg \t 40 deg \t 45 deg \t 50 deg \t 55 deg");
			System.out.println("===============================================================================================================");
			
			
			
			
		   
		}
}


its a work in progress. but what i am doing is trying to draw the values from my array list.
Was This Post Helpful? 0
  • +
  • -

#4 gibson.nathan   User is offline

  • D.I.C Regular
  • member icon

Reputation: 8
  • View blog
  • Posts: 294
  • Joined: 06-October 09

Re: variable and methods

Posted 13 November 2009 - 05:33 PM

i have updates the tester class to include my array lists:

/**
 * Write a description of class CatapultTester here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
import java.util.ArrayList;
public class CatapultTester
{
	public static void main(String[] args)
	   {
		   ArrayList<Integer> speed = new ArrayList<Integer>();
		   speed.add(new Catapult(20));
		   speed.add(new Catapult(25));
		   speed.add(new Catapult(30));
		   speed.add(new Catapult(35));
		   speed.add(new Catapult(40));
		   speed.add(new Catapult(45));
		   speed.add(new Catapult(50));
		   
		   
		   ArrayList<Integer> angle = new ArrayList<Integer>();
		   angle.add(new Catapult(25));
		   angle.add(new Catapult(30));
		   angle.add(new Catapult(35));
		   angle.add(new Catapult(40));
		   angle.add(new Catapult(45));
		   angle.add(new Catapult(50));
		   angle.add(new Catapult(55));
	   


im aware i had some typos in my array lsit. i didnt notice them until i posted.

This post has been edited by gibson.nathan: 13 November 2009 - 05:37 PM

Was This Post Helpful? 0
  • +
  • -

#5 gibson.nathan   User is offline

  • D.I.C Regular
  • member icon

Reputation: 8
  • View blog
  • Posts: 294
  • Joined: 06-October 09

Re: variable and methods

Posted 13 November 2009 - 05:45 PM

okay, i got that , i simply forgot to declare them. but i have a new problem, and i dont understand this because i got it from an example...

/**
 * Write a description of class CatapultTester here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
import java.util.ArrayList;
public class CatapultTester
{
	public static void main(String[] args)
	   {
		   ArrayList<Integer> speed = new ArrayList<Integer>();
		   speed.add(new Catapult(20));
		   speed.add(new Catapult(25));
		   speed.add(new Catapult(30));
		   speed.add(new Catapult(35));
		   speed.add(new Catapult(40));
		   speed.add(new Catapult(45));
		   speed.add(new Catapult(50));
		   
		   
		   ArrayList<Integer> angle = new ArrayList<Integer>();
		   angle.add(new Catapult(25));
		   angle.add(new Catapult(30));
		   angle.add(new Catapult(35));
		   angle.add(new Catapult(40));
		   angle.add(new Catapult(45));
		   angle.add(new angle(50));
		   angle.add(new angle(55));
		   

			

		   
		}
}


when i try to compile it says cannot find symbol catapult constructor int

This post has been edited by gibson.nathan: 13 November 2009 - 05:51 PM

Was This Post Helpful? 0
  • +
  • -

#6 gibson.nathan   User is offline

  • D.I.C Regular
  • member icon

Reputation: 8
  • View blog
  • Posts: 294
  • Joined: 06-October 09

Re: variable and methods

Posted 14 November 2009 - 10:49 AM

im not sure if i explained my problem very well. im working on a program that calculates the trajectory of an object given its launch speed and its launch angle. i have two array lists. one for speed, and one for angle. i also have a method that given the speed and angle can calculate the distance that the object will go. i have everything i need besides what actually does the calculations, it gets kind of confusing at this point. i have to take each speed and angle and get the distance to fill a table. i made a new array called distance, what is confusing me though is how to take each value and calculate and so on and so on. i attached a picture of the table so it would be easy to get an idea of what i was talking about. i have been struggling trying to figure this out for the last few days. basically where i am at now im trying to have a for loop that takes each velocity and then a for loop inside that takes each angle and plugs them into my method, but i dont know how to actually construct the part that tells the methods which numbers to use. if you guys can help me figure this out it would be very appreciated.

to get a good idea the chart is something like this:

Attached Image

my current code is like this. i have tried changing alot of stuff, but i end up coming back to this.

/**
 * Write a description of class CatapultTester here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
import java.util.ArrayList;
public class CatapultTester
{
	public static void main(String[] args)
	{
		   ArrayList<Integer> speed = new ArrayList<Integer>();
		   speed.add(new Integer(20));
		   speed.add(new Integer(25));
		   speed.add(new Integer(30));
		   speed.add(new Integer(35));
		   speed.add(new Integer(40));
		   speed.add(new Integer(45));
		   speed.add(new Integer(50));
		   
		   
		   ArrayList<Integer> angle = new ArrayList<Integer>();
		   angle.add(new Integer(25));
		   angle.add(new Integer(30));
		   angle.add(new Integer(35));
		   angle.add(new Integer(40));
		   angle.add(new Integer(45));
		   angle.add(new Integer(50));
		   angle.add(new Integer(55));
		   
		   
		   

		   
		   ArrayList<Double> distance = new ArrayList<Double>();
		   for(int i = 0; i < angle.size(); i ++)
		   {
			   
			   

			   
		   }
		   
	
			//print header
			System.out.println("												 Projectile Distance (feet)");
			System.out.println("  MPH \t 25 deg \t 30 deg \t 35 deg \t 40 deg \t 45 deg \t 50 deg \t 55 deg");
			System.out.println("===============================================================================================================");
			
			
			
			
		   
		}
}


/**
 * Write a description of class Catapult here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
import static java.lang.Math.*;
public class Catapult
{
	public double launchSpeed, launchAngle, distanceFeet, distanceMeters, distance, speed, angle;
	public static final double accelerationDueToGravity = 9.8, speedFeetFactor = 3.28;
	
	
	
	
	

	public Catapult(double speed, double angle)
	{


	}
	
	
	
	public void distanceMeters()
	{
		
		distanceMeters = pow(speed, 2)  * Math.sin(2 * toRadians(angle)) / accelerationDueToGravity;
		
	}
	
	public void distanceFeet()
	{
		distanceFeet = distance * speedFeetFactor;
		
	}
}

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1