GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Tech FAQs  >  Programming  >  Java
Go To First  |  Previous Question  |  Next Question 
 Java  |  Question 323 of 928    Print  
can give answer to the folloing question


Question 2

You are in charge of implementing a Grand Prix Car Racing Results system for a sports magazine, to be used for entering and processing data concerning each
Formula 1 Grand Prix that has been run in the season.

As you know, each driver is part of the team, and has a number. At the end of each race, the driver who arrived first is assigned 9 points, and the following five drivers receive 6,4,3,2 and 1 point each. Drivers who come in after the sixth position do not score any points.

Some features of the main application class (the GRANDPRIX class) are show in Figure 6 (on page 13). The main application data arrays are populated from and saved in a relational database. Arrays drivers and teams contain lists of all drivers and teams participating. Array races contains details of all races run so far.

Class Race contains linked list of Placement objects, each corresponding to a driver who took part in the race. The Placement objects are placed in the linked list in order of arrival. Some details of the Race and Placement classes are shown in Figure 5 (on page 13). Some details of the Driver and Team classes are also given.

(a) Class Placement has a creation routine:

public Placement (Driver d, int timeTaken, Boolean hasCompleted)

which is called by the main data entry routine at the end of a race. Write the code for this routine.


(b) In class Race, write a routine:

public int getTeamPoints (Team t) { … }

which return the total number of points gained in the race by a particular
team t. Assume the placements data for the race is fully entered.


(c) In the main application object, a printout of the overall point situation for all teams is required. For each team, the score at each race where points were gained is detailed, and the total score is given. An example of such a printout is shown in Figure 7 (on page 14). In class GrandPrix, write a routine :

public void printTeamPoints () { …. }

that will perform this task. The order in which teams are shown need not depend on points.
Figure 5: Fragment from classes Race, Placement, Driver and Team.


Import java.util.* ;

public class Race {

private String name; // E.g. Italy, South Africa, Malaysia etc
private Date date;
private Vector orderOfArrival; //Container for the placements

private static int points() = { 9,6,4,3,2,1};

……..
}



public class Placement {

private Driver driver;
private Team team;
private int timeTaken;
private Boolean hasCompleted;

…….
}


public class Driver {

private String name;
private String country;
private Team team;
private int number; // The competitor number on the car

…….

}


public class Team {

private String name; // E.g. McLaren, Benetton, Ferrari, etc
private String country;

…..
}
Figure 6 : Fragment from the Main Application Object.


public class GrandPrix {

feature
private Driver drivers();
private Team teams();
private Race races();
}



Figure 7 : Sample output for routine print_team_points.

Benetton
Argentina – 10 points
Germany – 3 points
Brazil – 7 points
** TOTAL : 20 points **

McLaren
Argentina – 3 points
Italy – 7 points
Germany – 6 points
Brazil – 10 points
** TOTAL : 26 points **

Old Bangers
** TOTAL: 0 points **

Ferrari
Italy – 5 points
Germany – 2 points
** TOTAL : 7 points **


……..










  
Total Answers and Comments: 0 Last Update: November 17, 2005     Asked by: hari2 
  
 Sponsored Links

 

No answers are posted for this question yet.
Be the first to answer it!


 Related Questions

As of now ,what i know abt cloning is that we can make a field to field copy of an object.ie when we clone an object,its state as well as a its behaviour is copied to the cloned object.My question is what is the neccesity of it? cant we create another object of the same class? so how does its different from cloned object (that is creating another object of that class rather than  being cloned).is there any security issues coupled with this cloned object? And What is the Concrete purpose of

Latest Answer : there are few step to use Log4J in you java code. 1- creat a file name log.properties with following text log4j.rootLogger=debug, stdout, R  log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout  # ...

Latest Answer : No it won't work.Only one main methods is allowed ...

Latest Answer :  In c,there are argc and argv.argc is passed to argv and argv is used to store characters.in java there is only args.we pass a String value to it. ...

Latest Answer : Abstract class can have instance variable, static variable, constructor, abstract methods, concrete methods, instance blocks and static blocks.Subclass has to extend abstract class using extend keyword. ...
Tags : Abstract

Latest Answer : In singleton class ,only one time the instance wil create.Example....public class Sin{  static Sin s=null;    public static void main(String a[])  {      create();     create();     ...

Latest Answer : The static variable is used to Synchronize (Ex: in seaphores…) the threads because it maintains the single copy for all the instances. We can call the static variable by the class name or from the reference. It stored in a Data segment. ...

Latest Answer : Below are three signatures:public final void notify()public final void notifyAll()public final void wait(long timeout) ...

Latest Answer : A Java Bean is a reusable software component that can be visually manipulated in builder tools.  To understand the precise meaning of this definition of a Bean, clarification is required for the following terms:   1. Software component: Reusable ...

Latest Answer : Methods cannot be overloaded only on the basis of return type atleast one argument should be different, otherwise compiler will give the message "The function is already defined in the class". ...


 Sponsored Links

 
Related Articles

Service Oriented Java Business Integration Review

Service Oriented Java Business Integration Review Introduction If you ve read through the texts which give you an introduction to SOA or Web Services you will often find them to be quite frustrating and the reason for this is because they spend too much time referencing business processes which are
 

Breaking up XML into Relational Data

Breaking up XML into Relational Data While the preceding example shows how to construct an XML representation over relational data the example in this section illustrates how you can shred XML data back into relational data This reverse operation can be useful if your application works with relation
 

Querying Data with Oracle XQuery

Querying Data with Oracle XQuery Starting with Oracle Database 10g Release 2 you can take advantage of a full featured native XQuery engine integrated with the database With Oracle XQuery you can accomplish various tasks involved in developing PHP Oracle XML applications operating on any kind of dat
 

Retrieving XML Data

Retrieving XML DataTo retrieve XML data from an XMLType table you can use a SELECT SQL statement just as you would if you had to query a relational table For example to select the employee with the id set to 100 from the employees XMLType table discussed in the preceding section you might issue the
 

Using XMLType for Handling XML Data in the Database

Using XMLType for Handling XML Data in the Database Being an object type XMLType can not only be used to store XML data in the database but also to operate on that data via its built in methods Regardless of the storage model you choose XMLType provides a set of XML specific methods to operate on XM
 

Using Oracle Database for Storing, Modifying, and Retrieving XML Data

Using Oracle Database for Storing Modifying and Retrieving XML Data With Oracle XML DB you have various XML storage and XML processing options allowing you to achieve the required level of performance and scalability One of the most interesting things about Oracle XML DB is that it allows you to per
 

Performing XSLT Transformations inside the Database

Performing XSLT Transformations inside the Database Now that you have the employees XSL stylesheet stored in the database and the xmlusr schema is permitted to access the hr employees table you can create a script that will instruct the database to build an HTML page based on the data stored in hr e
 

Moving All the XML Processing into the Database

Moving All the XML Processing into the Database In the preceding example the database server performs only a part of the XML processing while the rest is still performed by the PHP engine Specifically the database server generates an employees XML document based on the records from the hr employees
 

Performing XML Processing inside the Database

Performing XML Processing inside the Database When building XML enabled applications on top of Oracle there are many advantages to performing the XML processing inside the database when compared to performing it on the client The key advantages to perform XML processing inside the database are as fo
 

Transforming and Processing XML with XSLT

Transforming and Processing XML with XSLT In the preceding example you transform XML into HTML directly in your script wrapping the data extracted from the XML document into appropriate HTML tags Alternatively you might perform an XSL Extensible Stylesheet Language transformation to get the same gen
 

About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape