Solved

Object Oriented Concepts (Preferably java) - Looking for Pseudocode

Posted on 2008-10-23
3
470 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Eclipse with various Java releases 7 89
listing all the respondents to a twitter feed - Java 5 48
MFC COM Server not showing  form 4 26
Overriding a method 3 13
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

751 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