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
Solved

Object Oriented Concepts (Preferably java) - Looking for Pseudocode

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
iterator/ListIterator approach 17 39
runtime exception 2 41
Facing this issue for maven proxy setting 2 20
swing controls 2 16
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.
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.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

839 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