我们老师要一份JAVA大作业,但是我不会,想让帮帮我写一个不能太短的程序

我们没有学过数据库,所以程序中不要有关于数据库的,我们学的不多所以不要太复杂
谢谢各位了
我很急
最好有讲解步骤用处

我刚做了一个java的小游戏,贪吃蛇,算是草稿版,比较粗糙,不知能否帮上忙!
import java.awt.*;
import java.awt.event.*;
public class GreedSnake //主类
{

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new MyWindow();

}

}
class MyPanel extends Panel implements KeyListener,Runnable//自定义面板类,继承了键盘和线程接口
{

Button snake[]; //定义蛇按钮
int shu=0; //蛇的节数
int food[]; //食物数组
boolean result=true; //判定结果是输 还是赢
Thread thread; //定义线程
static int weix,weiy; //食物位置
boolean t=true; //判定游戏是否结束
int fangxiang=0; //蛇移动方向
int x=0,y=0; //蛇头位置
MyPanel()
{

setLayout(null);
snake=new Button[20];
food=new int [20];
thread=new Thread(this);

for(int j=0;j<20;j++)
{
food[j]=(int)(Math.random()*99);//定义20个随机食物
}

weix=(int)(food[0]*0.1)*60; //十位*60为横坐标
weiy=(int)(food[0]%10)*40; //个位*40为纵坐标
for(int i=0;i<20;i++)
{
snake[i]=new Button();
}

add(snake[0]);
snake[0].setBackground(Color.black);
snake[0].addKeyListener(this); //为蛇头添加键盘监视器
snake[0].setBounds(0,0,10,10);
setBackground(Color.cyan);
}

public void run() //接收线程
{

while(t)
{

if(fangxiang==0)//向右
{
try
{
x+=10;
snake[0].setLocation(x, y);//设置蛇头位置

if(x==weix&&y==weiy) //吃到食物
{
shu++;
weix=(int)(food[shu]*0.1)*60;
weiy=(int)(food[shu]%10)*40;
repaint(); //重绘下一个食物
add(snake[shu]); //增加蛇节数和位置
snake[shu].setBounds(snake[shu-1].getBounds());
}
thread.sleep(100); //睡眠100ms
}
catch(Exception e){}
}
else if(fangxiang==1)//向左
{
try
{
x-=10;
snake[0].setLocation(x, y);
if(x==weix&&y==weiy)
{
shu++;
weix=(int)(food[shu]*0.1)*60;
weiy=(int)(food[shu]%10)*40;
repaint();
add(snake[shu]);
snake[shu].setBounds(snake[shu-1].getBounds());
}

thread.sleep(100);
}
catch(Exception e){}
}
else if(fangxiang==2)//向上
{
try
{
y-=10;
snake[0].setLocation(x, y);
if(x==weix&&y==weiy)
{
shu++;
weix=(int)(food[shu]*0.1)*60;
weiy=(int)(food[shu]%10)*40;
repaint();
add(snake[shu]);
snake[shu].setBounds(snake[shu-1].getBounds());
}
thread.sleep(100);
}
catch(Exception e){}
}
else if(fangxiang==3)//向下
{
try
{
y+=10;
snake[0].setLocation(x, y);
if(x==weix&&y==weiy)
{
shu++;
weix=(int)(food[shu]*0.1)*60;
weiy=(int)(food[shu]%10)*40;
repaint();
add(snake[shu]);
snake[shu].setBounds(snake[shu-1].getBounds());
}
thread.sleep(100);
}
catch(Exception e){}
}
int num1=shu;
while(num1>1)//判断是否咬自己的尾巴
{
if(snake[num1].getBounds().x==snake[0].getBounds().x&&snake[num1].getBounds().y==snake[0].getBounds().y)
{
t=false;
result=false;
repaint();
}
num1--;
}
if(x<0||x>=this.getWidth()||y<0||y>=this.getHeight())//判断是否撞墙
{
t=false;
result=false;
repaint();
}
int num=shu;
while(num>0) //设置蛇节位置
{
snake[num].setBounds(snake[num-1].getBounds());
num--;
}

if(shu==15) //如果蛇节数等于15则胜利
{
t=false;
result=true;
repaint();
}

}

}
public void keyPressed(KeyEvent e) //按下键盘方向键
{
if(e.getKeyCode()==KeyEvent.VK_RIGHT)//右键
{
if(fangxiang!=1)//如果先前方向不为左
fangxiang=0;

}
else if(e.getKeyCode()==KeyEvent.VK_LEFT)
{ if(fangxiang!=0)
fangxiang=1;

}
else if(e.getKeyCode()==KeyEvent.VK_UP)
{ if(fangxiang!=3)
fangxiang=2;

}
else if(e.getKeyCode()==KeyEvent.VK_DOWN)
{ if(fangxiang!=2)
fangxiang=3;

}
}

public void keyTyped(KeyEvent e)
{

}
public void keyReleased(KeyEvent e)
{

}
public void paint(Graphics g) //在面板上绘图
{
int x1=this.getWidth()-1;
int y1=this.getHeight()-1;
g.setColor(Color.red);
g.fillOval(weix, weiy, 10, 10);//食物
g.drawRect(0, 0, x1, y1); //墙
if(t==false&&result==false)
g.drawString("GAME OVER!", 250, 200);//输出游戏失败
else if(t==false&&result==true)
g.drawString("YOU WIN!", 250, 200);//输出游戏成功
}

}
class MyWindow extends Frame implements ActionListener//自定义窗口类
{
MyPanel my;
Button btn;
Panel panel;
MyWindow()
{
super("GreedSnake");
my=new MyPanel();
btn=new Button("begin");
panel=new Panel();
btn.addActionListener(this);
panel.add(new Label("begin后请按Tab键选定蛇"));
panel.add(btn);
panel.add(new Label("按上下左右键控制蛇行动"));
add(panel,BorderLayout.NORTH);
add(my,BorderLayout.CENTER);
setBounds(100,100,610,500);
setVisible(true);
validate();
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e)//按下begin按钮
{

if(e.getSource()==btn)
{
try
{
my.thread.start(); //开始线程
my.validate();
}
catch(Exception ee){}
}

}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-11-14
package Teacher;

enum Operation {
PLUS{ double eval(double x, double y) { return x + y; }
// double eval(double x, double y,double z) { return x + y; }
},
MINUS{ double eval(double x, double y) { return x - y; }
// double eval(double x, double y,double z) { return x - y; }
},
TIMES{ double eval(double x, double y) { return x * y; }
// double eval(double x, double y,double z) { return x * y; }
},
DIVIDE{ double eval(double x, double y) { return x / y; }
// double eval(double x, double y,double z) { return x / y; }
};
// Do arithmetic op represented by this constant
abstract double eval(double x, double y);
// abstract double eval(double x, double y,double z);

}

public class EnumTest {
public static void main(String args[]) {

double x = 6.0;
double y = 2.0;

for (Operation op : Operation.values()) {
System.out.println(x + " " + op + " " + y + " = " + op.eval(x, y));
}

}
}本回答被提问者采纳
第2个回答  2008-11-14
public class BarChartDemo {
public BarChartDemo() {
super();
}

public static void main(String[] args) throws IOException{
CategoryDataset dataset = getDataSet();
JFreeChart chart = ChartFactory.createBarChart3D(
"招生信息总览", // 图表标题
"应报与实报对照", // 目录轴的显示标签
"人数", // 数值轴的显示标签
dataset, // 数据集
PlotOrientation.VERTICAL, // 图表方向:水平、垂直
true, // 是否显示图例(对于简单的柱状图必须是false)
true, // 是否生成工具
true // 是否生成URL链接
);
FileOutputStream fos_jpg = null;
try {
File file = new File("c:/student.png");
ChartUtilities.saveChartAsPNG(file,chart,400,300);
}finally {
try {
fos_jpg.close();
} catch (Exception e) {
String s = e.getLocalizedMessage();
s = e.getMessage();
s = e.toString();
}
}
}
/**
* 获取一个演示用的组合数据集对象
* @return
*/
private static CategoryDataset getDataSet() {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(200, "计划", "清华大学");
dataset.addValue(400, "实报", "清华大学");
dataset.addValue(100, "计划", "天津大学");
dataset.addValue(205, "实报", "天津大学");
dataset.addValue(200, "计划", "郑州大学");
dataset.addValue(285, "实报", "郑州大学");
return dataset;
}
}
第3个回答  2008-11-14
public class HelloWorld{
public static void main(String[] args]){
System.out.println("HelloWorld "+" WaHaHa");
}
}
第4个回答  2008-11-14
有一份研究生的作业,澳洲留学生的。不过程序是英文版的~~文档也是英文版的,而且文档还找不到了~-_-!
相似回答