Solved

Object Oriented Concepts (Preferably java) - Looking for Pseudocode

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This video teaches viewers about errors in exception handling.
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.

760 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

18 Experts available now in Live!

Get 1:1 Help Now