发现“cloudhy”同学的程序,有点小问题,完善如下:
/
1 模拟自由落体程序 程序描述:一个小球从100m高度自由落下,每次落地后反d跳回原高度的一半,再落下。编程实现:
1)求小球在第5次落地时,一共经过多少m?
2) 第5次反d高度多少m?
3) 将以上两个计算结果的输出。
/
public class FreeFallen {
/
计算第time次d起的高度
@param time d起的次数
/
public static double countHeight(int time) {
double height = 100; //应该是double类型的,第三次d起就是小数了
for (int i = 0; i < time; i++) {
height = height / 2;
}
return height;
}
/
计算第time次落地后经过的距离
@param time 落地的次数
/
public static double countDistance(int time) {
double distance = 100; //总距离
double each; //每次经过的距离
for (int i = 1; i < time; i++) {
//distance += distance / 2;
each = countHeight(i-1); //每次d起下落一回就等于上一次的高度,因为每次落地后反d跳回原高度的一半
distance += each;
}
return distance;
}
public static void main(String[] args) {
Systemoutprintln(countDistance(5));
Systemoutprintln(countHeight(5));
}
}
public static void main(String[] args) {
double h=100;
double sum=0;
for (int k = 1; k <=10; k++) {
sum+=h;
h=h05;
if(k!=10){
sum+=h;
}
}
Systemoutprintln(sum+","+h);
}
没办法了 只能注册一个马甲了
import javaawt;
import javaawtevent;
import javaawtGraphics;
public class yes {
public static void main(String args[])
{
Mywindow win=new Mywindow();
Ball qiu1=new Ball(5,5);
Thread thread1=new Thread(qiu1);
Ball qiu2=new Ball(10,5);
Thread thread2=new Thread(qiu2);
Ball qiu3=new Ball(15,5);
Thread thread3=new Thread(qiu3);
thread1start();
thread2start();
thread3start();
}
}
class Mywindow extends Frame {
Mywindow (){
setSize(350,350);
setVisible(true);
setBackground(ColorBLACK);
validate();
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
Systemexit(0);
}
});
}
}
class Ball extends Mywindow implements Runnable
{
int rgb=0;
Color color;
int x,y;
int dx=5,dy=5;
Ball(int x,int y){
thisx=x;
thisy=y;
}
public void doColor(){
rgb=(int)(Mathrandom()0xFFFFFF);
color=new Color(rgb);
}
public void paint(Graphics g){
gsetColor(color);
gfillOval(x,y,50,50);
}
public void run(){
while(true){
if(x<=0) {dx=5;doColor();}
else if((x+50)>=getWidth()) {dx=-5; doColor();}
if(y<=0) {dy=5;doColor();}
else if((y+50)>=getHeight()) {dy=-5; doColor();}
x=x+dx;
y=y+dy;
repaint();
try{Threadsleep(50);}
catch(InterruptedException e) {;}
}
}
}
你说的是模拟直线运动还是轨迹是抛物线的那种?
如何去模拟说白了就是要根据某种算法计算出物体运动的下一个坐标,做自由落体运动满足能量守恒定理,要把它实现出来关键是确定一个能量衰减(转化为其他能量)系数,就是物体以多少速度撞击然后以多少速度反d,以多少角度撞击和以多少角度反d,这个类似于镜面反射。
确定了以上这些,实现起来就不难了。
以小球每次落地之间所运行的路程数组成数列如下:
a0=n
a1=n/2+n/2=n
a2=n/4+n/4=n/2
a3=n/8+n/8=n/4
从a1开始往后,就可以看做是一个等比数列,比例q=05
对这个等比数列求和,得到和为:a1(1-q^n)/(1-q),当n趋于无穷大时,q^n=0,可以得到和为:n/(1-05)=2n,
整个数列之和就是小球运动的总路程=n+2n=3n米。
以上就是关于java自由落体题全部的内容,包括:java自由落体题、java程序 一球从h米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在第k次落、JAVA做一个作业,制作一个window框里面有三个小球碰撞,碰到边框或者小球变色加反d,错误代码求指点等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)