Results 1 to 7 of 7
Thread: Moving a car game in java
- 03-25-2011, 12:30 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 3
- Rep Power
- 0
Moving a car game in java
Hello guys;
I need some help about hw i need to do a car game its so basic but i cant reach what i need to do the description about hw is like that
Problem Description:
We would like to write a program about cars that can move along a single dimensional axis (E.g. x axis). Your job is to design, implement and test a car class which has the following properties:
Brand, Model, ModelYear, color, engineSize, fuelTankVolume, positionX, direction.
The car class should have the following basic behaviors
Getters/setters (Accessors, mutators): declare all fields private and write getter/setter methods for each.
Methods:
moveforward: Cars can only move if they have enough fuel. For each step (movement) cars consume their fuel accordingly to the following formula engineSize/1000*4. Move the car in the moveSpeed*MaxWeight/Weight. positionX must be updated accordingly.
changeDirection: reverses the direction faced.
print: prints all the datafields and especially current fuel left, positionX and direction.
• The car class must have shared (static) datafields moveSpeed, maxWeight, numberOfCars, maxWeight.
• Assume maximum car weight can be a constant value, e.g. 2000kg.
• Assume moveSpeed is non-constant value, e.g. 5.
• The class should have a no-argument constructor which assigns meaningful initial values.
• The class must have an argument constructor which assigns given brand, model, modelYear, colour, engineSize, fuelTankVolume, positionX, direction.
• The class also should be aware of how many cars (instances) are created during the program. Use numberOfCars in constructors to achieve this.
a) Draw the UML diagram of the cars class
b) Implement the class.
c) Write a tester class which invokes carSim1 method which creates a car prints the car, moves it, changes direction, and moves again few times, and prints again.
d) Write another method carSim2 method which creates 10 cars (use an array), invokes print for each of them. Then makes them move, change direction RANDOMLY and print again to see the fuel volume.
.
:)
Its a bit long but i need to do this if someone help me about this i will be pleased.
- 03-25-2011, 01:48 AM #2
Homework dumps aren't welcome here. Give it your best shot and ask a specific question.
How to ask questions the smart way
db
- 03-25-2011, 09:32 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 3
- Rep Power
- 0
public class Cars {
public String brand;
public String model;
public int modelyear;
public String color;
public double enginesize;
public int fueltankvolume;
public int positionx;
public Cars(){
brand = "Opel";
model = "Astra";
modelyear = 2011;
color = "Black";
enginesize = 1.6;
fueltankvolume = 100;
}
public Cars(String nbrand,String nmodel,int nmodelyear,String ncolor,double nenginesize,int nfueltankvolume){
brand = nbrand;
model = nmodel;
modelyear = nmodelyear;
color = ncolor;
enginesize = nenginesize;
fueltankvolume = nfueltankvolume;
}
public void printcar(){
System.out.println(brand);
System.out.println(model);
System.out.println(modelyear);
System.out.println(color);
System.out.println(enginesize);
System.out.println(fueltankvolume);
}
public static void main(String[] args){
Cars c1 = new Cars();
Cars c2 = new Cars("Fiat","Albea",2010,"Red",1.4,200);
c1.printcar();
c2.printcar();
}
}
i have problems with writing getters and setters. help please
- 03-25-2011, 11:39 PM #4
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
Did you read Darryl's link?i have problems with writing getters and setters.
You have problem writing getters and setter for what? Where is the code you tried to write (I don't see any methods that start with "get.." or set..")? What problems are you having? We are not mind readers.
- 03-26-2011, 12:40 PM #5
Member
- Join Date
- Mar 2011
- Posts
- 3
- Rep Power
- 0
Ive done getters and setter but i dont know where to put and how to write this methods Methods:
moveforward: Cars can only move if they have enough fuel. For each step (movement) cars consume their fuel accordingly to the following formula engineSize/1000*4. Move the car in the moveSpeed*MaxWeight/Weight. positionX must be updated accordingly.
changeDirection: reverses the direction faced.
- 08-12-2011, 06:17 AM #6
I think you are making stuff way to complicated for yourself. Are you going to a gaming school, because this seems like something right out of a text book. Regardless, you seem to have everything you need, if you know java, then you should be able to figure this out.
Do you know how to use KeyEvents?.gif)
Do you know how to use Thread?.gif)
Do you know how to use Java Swing?
- 08-12-2011, 07:13 AM #7
Similar Threads
-
Moving java shapes with mouse and buttons
By Haraldjjones in forum New To JavaReplies: 1Last Post: 01-20-2011, 09:26 PM -
Moving control backwards within loop in java
By jharishabh7 in forum New To JavaReplies: 16Last Post: 10-07-2010, 04:20 PM -
Java applet won't run since moving to Win 7 64 bit.
By bilzmale in forum New To JavaReplies: 3Last Post: 08-01-2010, 11:17 AM -
Moving files in Java
By techbossmb in forum Advanced JavaReplies: 1Last Post: 10-09-2009, 01:55 PM -
Need Help with Java 2d - moving train
By rtm09 in forum New To JavaReplies: 7Last Post: 04-15-2009, 12:28 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks