| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 684 人关注过本帖
标题:我要死了
只看楼主 加入收藏
lyym88
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2006-1-17
收藏
 问题点数:0 回复次数:7 
我要死了

谁能帮我做这个啊
CP2004 Assignment 2

due:week 12, friday at 5 pm

In Assignment 1 you wrote a program to simulate the shooting of a projectile straight up into the air. Most canon, however, don’t fire their shells straight up but at an angle. In Assignment 2 we will simulate the firing of the canon at an angle. This will involve altering the code we wrote in Assignment 1. Remember that in Assignment 1 we were mostly concerned with how the data was to be modelled. Since Assignment 2 includes a Graphical User Interface we talk about writing code to view the data.

Task

Write a Java program that simulates the shooting of a projectile at an angle up into the air, and a GUI that allows us to see the path of the projectile. First, let’s find a way to simulate the calculation of the position of the projectile, taking the starting angle of the canon into account.

If the starting velocity is v and the starting angle is a then the velocity is a vector with the components:

vx = v * cos(a) and vy = v * sin(a).

We can say that in the x (horizontal) axis the velocity of the projectile does not change. However, in the y (vertical) axis gravity plays its part and drags the projectile back to earth. So we need to calculate the x and y components of the location and velocity of the projectile separately.

We can now repeat the simulation from Assignment 1 but this time we update the x and y components separately. The steps we need to take are:

a) Rewrite the constructor for the Projectile class so that it takes both the initialVelocity and the initialAngle in Radians. The constructor needs to initialise both the xPosition and the yPosition of the projectile to 0. Then it should calculate the x component of the initial velocity by multiplying the cosine of the initial angle in Radians by the initialVelocity, and the y component of the initial velocity by multiplying the sine of the initial angle in Radians by the initialVelocity. (Give these variables suitable names.)

b) Rewrite the move() method in the Projectile class so that both the xPosition and the yPosition are calculated by adding each velocity component (x and y) multiplied by the time interval to the appropriate current position (so the x one gets added to the xPosition and the y one gets added to the yPosition).

c) Create a new variable that keeps count of the number of times the move method is used – call it numMoves. Increment this in the moves() method.

d) Write getters for each variable – there should be 5 variables:

a. 2 for the x and y components of the velocity

b. 2 for the x and y components of the position

c. and 1 for the number of moves.

e) Hard-code the following two variables:

private static final double GRAVITY = 9.81;

private static final double TIME_INTERVAL = 0.01;

Next we need to write the GUI. This is made up of two classes:

1) MainFrame, which extends JFrame and also contains the public static void main method. MainFrame is 800 pixels wide and 400 deep. Its title is “Trajectory”. Make sure that you set the default close operation to something appropriate. MainFrame adds an instance of the next class to its content pane.

2) ProjectileComponent, which extends JComponent. ProjectileComponent has the following methods:

a. A constructor which takes an instance of MainFrame as a parameter and sets two variables (X_MAX and Y_Max) to be the x and y dimensions of the MainFrame instance. It also initialises X_MIN and Y_MIN to 0.

The constructor also uses two JOptionPanes to get the initial velocity and the initial angle as user input, the latter using Math.toRadians to convert the parsed input to radians.

b. An overridden version of paintComponent(Graphics g) which allows us to draw the projectile every n moves (try with n set to 10 perhaps). You get the number of moves from the getNumMoves() method which is in the Projectile class. Then, while the yPosition of the projectile is > 0 calculate the pixel positions of the projectile and draw a small circle at that point every n moves. Consider using Graphics2G to allow the easy drawing of small circles to represent the projectile.

c. Use the following code to help convert the user position to a pixel position:

/**

* Converts from user coordinates to pixel coordinates.

*

* @param xUser an x-value in user coordinates

* @return the corresponding value in pixel coordinates

*/

public double xPixel(double xUser) {

return (xUser - X_MIN) * (getWidth() - 1) / (X_MAX - X_MIN);

}

/**

* Converts from user coordinates to pixel coordinates.

*

* @param yUser a y-value in user coordinates

* @return the corresponding value in pixel coordinates

*/

public double yPixel(double yUser) {

return (yUser - Y_MAX) * (getHeight() - 1) / (Y_MIN - Y_MAX);

}

You might require other methods – the list above is not exhaustive.

Each class must be appropriately documented, using javadoc and comments as necessary.


Sample output

Using an initial velocity of 100, an initial angle 60 degrees, a short time interval of 0.01 and drawing the projectile every 20 moves I get:

NB – these are pictures from an Apple Mac – if you use MSWindows yours will look a bit different.
Requirements

Students are required to produce their own solutions to this task by constructing classes as outlined above using JDK1.4.2. The new Projectile class should be in a package called au.edu.jcu.cp2004.model and the GUI classes should be in a package called au.edu.jcu.cp2004.view. In addition, please include a short document (< 0.5 pages) detailing the status of you code and documentation (how complete it is), any known bugs in your code, and any assumptions in your testing.

Reading

a) You are also encouraged to make full use of the api javadocs.

b) For further details of some ballistics formulae, have a look at Michel Grimmick’s site:

http://www.xs4all.nl/~mdgsoft/catapult/ballistics.html.

c) Have a look at http://www.javaworld.com/javaworld/jw-04-1998/jw-04-howto.html for a detailed description of models and views, but only if you have time and are very keen!

Submission

An electronic copy of your assignment must be emailed to your lecturer by the due date. Your lecturer will announce that date during semester.

Marking Scheme
The assignment is worth 20% of your overall CP2004 grade.

Execution: 14 marks

a. Re-implementation of Projectile.java

1. Constructor (2 marks)

2. move() (2 marks)

3. getters (2 marks)

b. MainFrame – 2 marks

c. ProjectileComponent.java

1. Constructor with 2 OptionPanes which return Strings (2 marks)

2. Overriding paintComponent(Graphics g) (4 marks)

Coding: 6 marks

- Appropriate code organisation

- Javadoc comments and ordinary comments

- Code formatting (eg correct indenting of methods, loops and control statements) and code style (eg use of camelCase in naming variables and methods), including appropriate names for variables and methods

搜索更多相关主题的帖子: canon will however involve angle 
2006-02-02 22:39
lyym88
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2006-1-17
收藏
得分:0 

// this is the cp 2004 assignment 1

package au.edu.jcu.cp2004.model;
import java.io.*;


public class Cannon
{

BufferedReader speed ,interval;
String Stspeed,Stinterval;
double sp,in;

Projectile p = new Projectile();
public Cannon()
{
setInitialValues();
}

public void setInitialValues()// intial the value by user input
{
try{

System.out.println("Enter the intial speed ");
speed = new BufferedReader(new InputStreamReader(System.in));// user input
Stspeed = speed.readLine();

System.out.println("Enter the intial interval");
interval = new BufferedReader(new InputStreamReader(System.in));// user input
Stinterval = interval.readLine();

if( Stspeed.equals("")||Stinterval.equals(""))
{
System.out.println("USER NAME SHOULD NOT BE NULL");
System.out.println("");
setInitialValues();
}

}catch (IOException e) {
System.err.println("errors ");
return;
}

sp = Double.parseDouble(Stspeed);// String convet to double
in = Double.parseDouble(Stinterval);

if(sp<0 || in<0)
{
System.out.println(" you enter invaild number, so the program finished");// check ing the -1 for program finish
return;
}
else
{
fireShot(sp,in);// calling first fire shot function
}
}

public void fireShot(double s,double i)// calling the function print
{
p.printPositionAndVelocity(s,i);
}

public static void main(String args[])// main function
{
Cannon x = new Cannon();
}


}这个前面我已经做好了

2006-02-02 22:41
lyym88
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2006-1-17
收藏
得分:0 

/ this is the cp 2004 assignment 1

package au.edu.jcu.cp2004.model;
import java.io.*;


public class Projectile
{

public Projectile(){}

double currentv;
double currentp=0;
double intialp;
double intials;
double time;
double pass;
double[] values = new double[10];


public double getCurrentVelocity(double r,double q,double y)// get current speed, using recursive for this method
{
time =y;
if( time == 0 )// if time is 0, means speed is intial speed
{
currentv = r;
return currentv;
}
else// eles the speed is the old speed - the change of the speed
{
currentv = currentv - ( 9.81 * ( 1 + q ) );
return currentv;
}
}

public double getPosition(double m,double t,double y)// get the postion using recursive for this method
{
/*double k = getCurrentVelocity(double m)
currentp = getPosition() + (-(0.5*9.81*1)+(k*1));

//-(0.5 * g * t) + (v * t)

return currentp;*/
double tcs = getCurrentVelocity(m,t,y);
time =y;
if( time == 0)
{
currentp = 0;
//return currentp;
//tcs
// currentp = currentp + (-(0.5*9.81*1)+(tcs*1));
}
// else
// {
// double tcs = getCurrentVelocity(m,t,y);
//System.out.println(tcs);
currentp = currentp + (-(0.5*9.81*1)+(tcs*1));// the position is the old position + the new speed run at 1 sec the position
//System.out.println(currentp);
return currentp;
// }
}


public void printPositionAndVelocity(double s, double i)// printing function
{


System.out.println("After 0 sec Simulation the position is 0");
for( int y=0;y<10;y++)
{

//int x = y+1;
// System.out.println("speed is "+getCurrentVelocity(s,i,y));
//System.out.println(getPosition(s,i,y)+" "+getCurrentVelocity(s,i,y));

//int x = y+1;
//System.out.println("y is "+y+" "+ getCurrentVelocity(s,i,y));

int x = y+1;
System.out.println("After "+x+" sec Simulation the position is "+getPosition(s,i,y));
//System.out.println("The ballistic formula position is: "+getPosition(s,i,y));

//System.out.println( getCurrentVelocity(s,i,y));

//int x = y+1;
//System.out.println(" After "+" "+x+": Simulation position: " + getPosition(s,i,y) + " "+"Velocity"+" "+getCurrentVelocity(s,i,x)+" "+"m/s");
//System.out.println("The ballistic formula position is:"+" "+getPosition(s,i,y));
}
System.out.println("");
for( int o=0;o<=10;o++)
{
System.out.println( "the Velocity in the "+o+" sec is "+getCurrentVelocity(s,i,o)+" m/s");
}

}
}

2006-02-02 22:41
lyym88
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2006-1-17
收藏
得分:0 
上面Assignment 1都是我前面做好的,谁能帮我把后面做好啊,谢谢大家了,这个很难不是一搬能做的,希望大家一起讨论
2006-02-02 22:43
gaohua_3
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2005-11-21
收藏
得分:0 

什么呀??

2006-02-10 11:34
燃烧
Rank: 1
等 级:新手上路
帖 子:3267
专家分:1
注 册:2006-2-6
收藏
得分:0 

汗汗汗
这么...

Give me a world !   A beautiful world !
2006-02-13 15:07
weizheng
Rank: 1
等 级:新手上路
威 望:2
帖 子:286
专家分:0
注 册:2005-4-21
收藏
得分:0 
水平真高啊!!!
自叹不如

温和如玉,完美纯正。
2006-02-14 17:15
Jhyvin
Rank: 2
等 级:新手上路
威 望:4
帖 子:81
专家分:0
注 册:2005-12-29
收藏
得分:0 

发帖不能用这样的名字 自己改改 否则删帖


一万年太久,只争朝夕! 从此不再乱翻书!!!
2006-02-14 19:56
快速回复:我要死了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024337 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved