Hello,

I have a problem with this method:

public boolean addRaceDrivertoTeam(String driverLicenseNumber,String  
            nationality,String constructorName, String fullName, Date dateOfBirth 
            , int worldChampionships, int totalScore, int highestRaceFinish){ 
        RaceDriver driver = new RaceDriver(driverLicenseNumber,fullName,nationality, 
                dateOfBirth,worldChampionships,totalScore, highestRaceFinish); 
        Constructors con; 
        con = Constructors.valueOf(constructorName); 
        RaceTeam team= new RaceTeam(con); 
        if (driver.getRaceDriverKey()!=null) 
            if (raceTeam.containsKey(con)&&(driver != null)  &&  
                    !team.isDriverExists(driver)){ 
                team.addRaceDriver(driver); 
                return true; 
                } 
        return false; 
        }

This method should add RaceDriver to Team, the method word correctly, but there is one mistake.
every Team can include just at 3 drivers .

I didn't know how I can limit it/

i try limit it from the addRaceDriver() method that in the RaceTeam class but i didn't succed.
this is the addRaceDriver() method:

public boolean addRaceDriver(RaceDriver driver){ 
         
        if (raceDriver != null && !raceDriver.containsKey(driver.getRaceDriverKey())){ 
            raceDriver.put(driver.getRaceDriverKey(), driver); 
            return true; 
        } 
        return false; 
        }

anyone can help me how to do this ?

Why not check for raceDriver.size()>3 in the if condition in addRaceDriver.

I try to do this:

public boolean addRaceDriver(RaceDriver driver){
		if (raceDriver!=null && raceDriver.size()>2)
			return false;
		if (raceDriver != null && !raceDriver.containsKey(driver.getRaceDriverKey())){
			raceDriver.put(driver.getRaceDriverKey(), driver);
			return true;
		}
		return false;
		}

but it's didn't help !!!

I try to change in the method, maybe one of the two methods is wrong because id the addRaceDrivertoTeam() method return:
return team.addRaceDriver(driver);
and the method returns false :(!!!

maybe that meaning that the wrong from addRaceDriver() method !!

this is the methods:

this method in sys class:

public boolean addRaceDrivertoTeam(String driverLicenseNumber,String 			nationality,String constructorName, String fullName, Date dateOfBirth			
, int worldChampionships, int totalScore, int highestRaceFinish){		
RaceDriver driver = new RaceDriver(driverLicenseNumber,fullName,nationality,				dateOfBirth,worldChampionships,totalScore, highestRaceFinish);		
Constructors con;		
con = Constructors.valueOf(constructorName);		
RaceTeam team= new RaceTeam(con);		
if (driver.getRaceDriverKey()!=null)			
if (raceTeam.containsKey(con)&&(driver != null)  && 					!team.isDriverExists(driver)){ 				
return team.addRaceDriver(driver);				
}		
return false;		
}

and this in RaceTeam class:

public boolean addRaceDriver(RaceDriver driver){ 		
if (raceDriver != null && raceDriver.containsKey(driver.getRaceDriverKey())){
raceDriver.put(driver.getRaceDriverKey(), driver);			
return true;		
}		
return false;		}

this is the prototype for th sys class:

protected Map <String, RaceCar> raceCar =new HashMap<String, RaceCar>();	
protected Map <String, Race> race =new HashMap<String, Race>();	
protected Map <Constructors,RaceTeam>raceTeam=new HashMap<Constructors,RaceTeam>();	
protected Map <String, RaceTrack> raceTrack =new HashMap<String, RaceTrack>();

and this is for the RaceTeam class:

protected Constructors name;	protected int totalScore;	
protected URL website;	
protected double budget;	
protected String lastRace;	
protected Race race; 	
protected HashMap <String,RaceDriver> raceDriver;

where is the problem in this methods :( ???!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.