Solved

Object Oriented Concepts (Preferably java) - Looking for Pseudocode

Posted on 2008-10-23
3
468 Views
Last Modified: 2008-11-21
I have a requirement where i need to write Psuedocode. If the description is not clear,  please ask me questions. I need to present my OOPS concepts here.

Assume we are writing a simple car race program.  
We have 10 Cars in the race and we want to know what order the cars
are in.  So we will periodically call UpdateLeaderBoard.
 
Assume that we have a record or a structure, Car, in pseudo-code:
Car
    Name: String;
    StartPos: Int;
    CurPos: Int;
    Speed: Int;
end;
 
You can make it into an object if you want.

Assume for now that the track is straight.  We don't have to take
laps into account.   We are only concerned with distance from some
0 point.  To make it interesting, not all the cars start at the same point.
 
Position, here, refers to location on the track, not ranking on the LeaderBoard.

Assume that we can initialize the cars by reading data in from a file.
Something like
> proc InitCars
> begin
>    I = 0;
>    while I < 10 do
>    begin
>       ReadXML(Cars[I]);
>       Next(I)
>    end
> end

You can rework that however you want, but you can delegate the details
of reading the file if you want.  
 
The routine that calculates the leaders will be called several times
throughout the race to find the current ranking.
Show me, in pseudo-code or language of your choice, what that
overall program would look like.  Im especially interested in the
details of UpdateLeaderBoard and where it is called.
0
Comment
Question by:smaram1
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
RishadanPort earned 500 total points
ID: 22792381
Ok.

For now, I am going to declare a function called "UpdateCarPositions(Cars[])" which changes the current position of each car. And a function called "IsRaceFinished(Cars[])" which determines if a car has already won the race. We will suppose that both these functions work:
function CarRacingProgram
begin
Cars[] = InitCars() //This function is given
 
   while(IsRaceFinished(Cars) is not true)
      UpdateCarPositions(Cars)
      UpdateLeaderBoard(Cars)
      Pause certain amount of time
   end 
end
 
//This function prints out the current leaders
//and sorts Cars[] related to who is in the lead... index 0 refers to the leader ... index Cars.Length - 1 = last place
function UpdateLeaderBoard(Cars[])
begin
   //Insert your PseudoCode to sort Cars[] and print each name out to the screen
end

Open in new window

0
 
LVL 6

Expert Comment

by:RishadanPort
ID: 22792387
Your job is simply to sort the Cars[], by the the greatest "CurPos"

I obviously don't want to implement all of this for you... since this is your excersize
0
 

Author Comment

by:smaram1
ID: 22792905
Thanks for the reply.
this is a good start. Let me take this up and i will ask questions on this.
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
servlet doXXX methods 3 49
couple of eclipse 5 37
tomcat not starting 6 45
Chrome and Firefox Java 5 34
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question