I have some issues getting started on an assignment we got from the university.
We have to make a racetrack with 4 participants.
We need to make 3 class'.
RaceTrack which hold advance() and winner() + the start and finish line (start = 0, finish = whatever).
Cars which holds the 4 participants with carName (BMW, Opel, Ford) and carCountry (which country the participant is from).
Its always the same participants actually running the track.
and last, the Race which actually initiate the Race.
In the end, the winner needs to be announced using a Cowsay, which I already made.
Since this is our first week assignment, we're currently just working in the 'main' area. So to start the race it would probably look like this:
public static void main(String[] args) {
Race race1 = new Race();
race1.initialize();
}
but I'm not actually sure how to make all this happen.
I'm not looking for a direct solution (not yet anyway), just a hint to get started :)
What i've currently done is the following:
// Car.java
public class Car
{
private String country;
private String name;
public Car()
{
}
public Car(String name, String country)
{
this.country = country;
this.name = name;
}
public String getCountry()
{
return country;
}
public String getName()
{
return name;
}
}
// RaceTrack.java
public class RaceTrack {
private int trackStart;
private int trackEnd;
public void advance()
{
}
public void winner()
{
}
}
//Race.java
public class Race {
public void Race()
{
}
public static void main(String[] args)
{
Car car1 = new Car("Car De Moo", "Car of awesome");
Car car2 = new Car("Car De Old", "Car of NOTawesome");
Car car3 = new Car("Car Ze German", "Car of Nazi");
Car car4 = new Car("SuperCar", "Car of TOTALLY ORGASMIC!");
Cowsay winnerCar = new Cowsay();
winnerCar.display("Cartype, "+ car1.getName() +", from " + car1.getCountry() + ", won the race!");
}
}
Please don't mind the random names and countries :)---------- Post added at 04:45 PM ---------- Previous post was at 04:38 PM ----------
Oh yea.. Each car got to move independently using the random function, just in case you were wondering how "advance()" should work.
---------- Post added at 04:49 PM ---------- Previous post was at 04:45 PM ----------
Also, the cars advance one at a time, not all 4 at the same time. So the random function would probably also first figure out which car gets to move, and then how long it gets to move - All using ints.


Sign In
Create Account


Back to top









