Solved

Object Oriented Concepts (Preferably java) - Looking for Pseudocode

Posted on 2008-10-23
3
466 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
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…

930 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now