Results 1 to 5 of 5
  1. #1
    alrebatsd is offline Member
    Join Date
    Apr 2009
    Posts
    28
    Rep Power
    0

    Default help to solve tis problem in method

    Hello,

    I have a problem with this method:

    PHP Code:
    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:
    PHP Code:
    	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 ?

  2. #2
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    you can check the size of the collection b4 adding driver.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  3. #3
    alrebatsd is offline Member
    Join Date
    Apr 2009
    Posts
    28
    Rep Power
    0

    Default

    Hello'
    I do this and added a new check:

    PHP Code:
    if (driver.getRaceDriverKey()!=null) 
                if (raceTeam.containsKey(con)&&(driver != null)  &&  
                        !team.isDriverExists(driver) && (raceTeam.size()<3)){ 
                    team.addRaceDriver(driver); 
                    return true; 
                    }
    but it's didn't help !!!

  4. #4
    alrebatsd is offline Member
    Join Date
    Apr 2009
    Posts
    28
    Rep Power
    0

    Default

    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:
    PHP Code:
    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:
    PHP Code:
    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:
    PHP Code:
    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:
    PHP Code:
    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 :( ???!!
    Last edited by alrebatsd; 06-07-2009 at 12:50 PM.

  5. #5
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    I haven't a clue, maybe writing a small test program will help.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

Similar Threads

  1. Factory problem: How to Solve it
    By rahul_capricorn in forum Threads and Synchronization
    Replies: 2
    Last Post: 02-11-2009, 05:47 PM
  2. Help me to solve problem
    By mansoorhacker in forum Forum Guides
    Replies: 8
    Last Post: 01-24-2009, 07:29 PM
  3. Factory problem: How to Solve it
    By rahul_capricorn in forum Advanced Java
    Replies: 1
    Last Post: 01-14-2009, 02:10 PM
  4. Solve my Problem
    By kyo in forum New To Java
    Replies: 1
    Last Post: 12-16-2008, 03:22 PM
  5. Help me to solve problem
    By mansoorhacker in forum New To Java
    Replies: 3
    Last Post: 11-13-2008, 09:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •