「java编写赛车」java赛车游戏源代码
今天给各位分享java编写赛车的知识,其中也会对java赛车游戏源代码进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、JAVA 赛车游戏
- 2、java利用多线程编写赛马程序
- 3、Java编写汽车类car
- 4、请问如何用Java编写一个汽车类Car
- 5、1. 编写一个Java应用程序,设计一个汽车类Vehicle,包含的成员属性有:车轮个数wheels和车重weight。
JAVA 赛车游戏
九百多K的也很多,不知你说哪个,3D的赛车游戏我有很多,像E
A的速度与激情系列就不错,可以去游戏网站搜赛车类的
java利用多线程编写赛马程序
package ThreadTest;
public class HorseRacing
{
public static void main(String[] args) {
Herose black = new Herose("黑马" , 19 , 1000); // new Herose(名称,最大速度 , 赛道总长)
Herose white = new Herose("白马" , 18 , 1000);
Herose red = new Herose("红马",20 , 1000);
black.race();
white.race();
red.race();
}
}
package ThreadTest;
import java.util.Timer;
public class Herose{
private String name;
private int maxSpeed;
private int distance;
public Timer timer = new Timer();
public void race(){
Runnable runnable = new Runnable(){
public void run(){
int Min = 1;
int Max = getMaxSpeed();
int i = 0;
int myDistance = getDistance();
int position = 0;
int nowSpeed = Min + (int)(Math.random() * ((Max - Min) + 1));
while( 0 myDistance ){
if( i 0 i % 10 == 0 ){
nowSpeed = Min + (int)(Math.random() * ((Max - Min) + 1));
position = getDistance()- myDistance;
System.out.println( i + "秒 : " + getName() + " 位置为 " + position + "m" + " 当前速度为 " + nowSpeed +"m/s");
}
++i;
myDistance = myDistance - nowSpeed;
if(myDistance = 0){
System.out.println( i + "秒 : " + getName() + "到达终点!");
}
try
{
Thread.sleep( 1000); //间隔1000毫秒 = 1秒
} catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
};
new Thread(runnable).start();
}
public Herose(String name, int maxSpeed , int distance)
{
this.name = name;
this.maxSpeed = maxSpeed;
this.distance = distance;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public int getMaxSpeed()
{
return maxSpeed;
}
public void setMaxSpeed(int maxSpeed)
{
this.maxSpeed = maxSpeed;
}
public int getDistance()
{
return distance;
}
public void setDistance(int distance)
{
this.distance = distance;
}
}
Java编写汽车类car
public class Car {
private int num;//编号
private String name;//型号
private double price;//单价
/**
* 无参构造
*/
public Car(){
super();
}
/**
* 有参构造
* @param num
* @param name
* @param price
*/
public Car(int num, String name, double price) {
super();
this.num = num;
this.name = name;
this.price = price;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String inforShow() {
return "Car [num=" + num + ", name=" + name + ", price=" + price + "]";
}
}
public class PriCar extends Car{
private int PersonNum;//最大载客量
public PriCar(int personNum) {
super();
PersonNum = personNum;
}
public PriCar() {
super();
}
public int getPersonNum() {
return PersonNum;
}
public void setPersonNum(int personNum) {
PersonNum = personNum;
}
@Override
public String inforShow() {
return "PriCar [PersonNum=" + PersonNum + "]";
}
}
public class VanCar extends Car {
private double weight;//最大载重
public VanCar(double weight) {
super();
this.weight = weight;
}
public VanCar() {
super();
}
@Override
public String inforShow() {
return "PriCar [num=" + super.getNum() + ", name=" + super.getName() + ", price=" + super.getPrice() +",weight=" + weight + "]";
}
}
测试类不想写了 应该可以自己写出来了吧
请问如何用Java编写一个汽车类Car
public class Car {
private String color;//颜色
private int door;//车门数量
private float speed;//车速
public Car(){
this.color = "红色";
this.door = 3;
this.speed = 110;
}
public Car(String color, int door, float speed) {
this.color = color;
this.door = door;
this.speed = speed;
}
public void start(){
//汽车启动。输出汽车已启动,并输出汽车的各个属性
System.out.println("汽车已启动,汽车颜色为"+color+",车门数为"+door+",车速为"+speed);
}
public void speedUp(float speed){
//加速
System.out.println("汽车加速到"+speed+"km/h");
}
public void shutDown(float speed){
//减速
System.out.println("汽车减速到"+speed+"km/h");
}
public void brake(){
//刹车
System.out.println("已刹车");
}
}
public class Test {
public static void main(String[] args){
Car car = new Car();
car.start();
car.speedUp(100);
car.shutDown(60);
car.brake();
Car car1 = new Car("白色",4,20.2F);
car1.start();
car1.speedUp(100);
car1.shutDown(60);
car1.brake();
}
}
运行结果
1. 编写一个Java应用程序,设计一个汽车类Vehicle,包含的成员属性有:车轮个数wheels和车重weight。
classVehicle{privateintwheels;privatefloatweight;protectedVehicle(intwheels,floatweight){this。wheels=wheels;this。weight=weight。是普通的除号,即10/2=5。
编写java程序的注意事项:
大小写敏感:Java是大小写敏感的,这就意味着标识符Hello与hello是不同的。
类名:对于所有的类来说,类名的首字母应该大写。如果类名由若干单词组成,那么每个单词的首字母应该大写,例如 MyFirstJavaClass。
方法名:所有的方法名都应该以小写字母开头。如果方法名含有若干单词,则后面的每个单词首字母大写,例如myFirstJavaClass。
关于java编写赛车和java赛车游戏源代码的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。