Imports in 100% Java

In real Java we don't need to import other robots if they are defined in the kareltherobot package.

To put your robot definitions in separate files, do this.

Put a FieldHarvester class in a file named FieldHarvester.java. Mark the class public in this file. Put a package statement at the very beginning of this file also.

package kareltherobot;

public class FieldHarvester extends Harvester
{	public FieldHarvester(int Street, int Avenue, Direction direction, int numberOfBeepers)
	{	super(Street, Avenue, direction, numberOfBeepers);
	}

	public void harvestField() 
	{	move();
		harvestTwoRows();
		positionForNextHarvest();
		harvestTwoRows();
		positionForNextHarvest();
		harvestTwoRows();
		move();
	} 	
}

Then, other robot classes will be able to use this without saying anything special. However, you must make sure that this file gets compiled by your system. If you use a java IDE to write your Karel programs, just make sure that the above file is part of your project.

However, if you do want to use an import and FieldHarvester is part of the kareltherobot package, then the correct import would be

import kareltherobot.FieldHarvester;

This is because the package name is part of the full name of any class.

If you use other java code from other packages you will need to import the code, however. For example, I furnish a package called cs1 that has a Die class that you can use to roll dice for games and such. To use this class you would say

import cs1.Die;

at the beginning of a file that needed to create and use a Die object.