Results 1 to 7 of 7
  1. #1
    AlpTTT is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default 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.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,416
    Rep Power
    20

    Default

    Homework dumps aren't welcome here. Give it your best shot and ask a specific question.

    How to ask questions the smart way

    db

  3. #3
    AlpTTT is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default

    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

  4. #4
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    i have problems with writing getters and setters.
    Did you read Darryl's link?

    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.

  5. #5
    AlpTTT is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default

    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.

  6. #6
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default

    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?
    Do you know how to use Thread?
    Do you know how to use Java Swing?

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,416
    Rep Power
    20

Similar Threads

  1. Moving java shapes with mouse and buttons
    By Haraldjjones in forum New To Java
    Replies: 1
    Last Post: 01-20-2011, 09:26 PM
  2. Moving control backwards within loop in java
    By jharishabh7 in forum New To Java
    Replies: 16
    Last Post: 10-07-2010, 04:20 PM
  3. Java applet won't run since moving to Win 7 64 bit.
    By bilzmale in forum New To Java
    Replies: 3
    Last Post: 08-01-2010, 11:17 AM
  4. Moving files in Java
    By techbossmb in forum Advanced Java
    Replies: 1
    Last Post: 10-09-2009, 01:55 PM
  5. Need Help with Java 2d - moving train
    By rtm09 in forum New To Java
    Replies: 7
    Last Post: 04-15-2009, 12:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •