Hi,

I have 4 classes , 1 is the base class and the other inherts from it,
it worked fine when compiling ..

I tried to make them as a package , it works fine with the superclass but it doesn't with the other classes,
It always gives me cannot find symbol error ..
Note: that all of them are on 1 directory ..
help please ..

package policies;
/**
  *	This the super class which all other classes inhertes from
  * it's an abstract class , with an abstract method!
  */

/**
 * Declaring the class
 */
public abstract class Policy
{
	/**
	 * Declaring veriables
	 */
	private int pnumber;
	private String name;
	private String adress;
	private int psdate;
	private int phone;
	static int lastpnumber;

	/**
	 * Making a class to hold date variables only
	 * @param "d,m,y" which holds day, month and year
	 */

	class Cal
	{
		public int d, m, y;
	}
	/**
	 * Creat two instances of the class Cal
	 */
	Cal dbirth = new Cal();
	Cal pedate = new Cal();


	/**
	 * <p>Policy constuctor<p>
	 */
	public Policy (String pname, String padress, int ppsdate, int pd , int pm, int py , int pphone, int pdobd, int pdobm, int pdoby)
	{
		pnumber = lastpnumber;
		name = pname;
		adress = padress;
		psdate = ppsdate;
		phone = pphone;
		pedate.d = pd;
		pedate.m = pm;
		pedate.y = py;
		dbirth.d = pdobd;
		dbirth.m = pdobm;
		dbirth.y = pdoby;
	}

	/**
	 * The following methods are to set and get the private variables
	 * of the Policy class
	 */
	public void setPnumber(int ppnumber)
	{
		pnumber = ppnumber;
	}

	public int getPnumber()
	{
		return pnumber;
	}

	public void setName (String pname)
	{
		name = pname;
	}

	public String getName()
	{
		return name;
	}

	public void setAdress (String padress)
	{
		adress = padress;
	}

	public String getAdress()
	{
		return adress;
	}

	public void setPsdate (int ppsdate)
	{
		psdate = ppsdate;
	}

	public int getPsdate()
	{
		return psdate;
	}

	public void setPedated (int ppedated)
	{
		pedate.d = ppedated;
	}

	public void setPedatem (int ppedatem)
	{
		pedate.m = ppedatem;
	}

	public void setPedatey (int ppedatey)
	{
		pedate.y = ppedatey;
	}

	public int getPedated()
	{
		return pedate.d;
	}

	public int getPedatem()
	{
			return pedate.m;
	}

	public int getPedatey()
	{
			return pedate.y;
	}

	public void setPhone (int pphone)
	{
		phone = pphone;
	}

	public int getPhone()
	{
		return phone;
	}

	public void setDobd (int pdobd)
	{
		dbirth.d = pdobd;
	}

	public int getDob ()
	{
		return dbirth.d;
	}

	public void setDobm (int pdobm)
	{
		dbirth.m = pdobm;
	}

	public int getDobm ()
	{
		return dbirth.m;
	}

	public void setDoby (int pdoby)
	{
		dbirth.y = pdoby;
	}

	public int getDoby ()
	{
		return dbirth.y;
	}

	/**
	 * The toString() method to return the values of the variables on the class
	 * @return variables values in a println format
	 */
	public String toString()
	{
		return ("Name: " + getName() + "\nPolicy number: " + "\nAdress: " + getAdress() + "\nStart Date: " + getPsdate() + "\nEnd Date: " + getPedated() + getPedatem() + getPedatey() + "\nPhone Number: " + getPhone() + "\nDate of Birth: " + getDob() + "-" + getDobm() + "-" + getDoby());
	}

	/**
	 * Declare an abstract class CalculatePremium
	 */
	public abstract int CalculatePremium();

}

The inheritance class

package policies;
/**
 * This class is an extended class of the Policy class
 * The Car class introduce new values that should be held
 * regarding cars policy
 */

/**
 * Import the Calender package
 */
import java.util.Calendar;

public class Car extends Policy
{
	private int cregnumber;
	private int year;
	private int CC;
	private int premium;

	/**
	 * Creating an instance of the Calender class
	 * @param "Cyear" an instance of Calender
	 * "y" an integer that will hold the current year value
 	 */
	Calendar cYear = Calendar.getInstance();
	int y = cYear.get(Calendar.YEAR);

	/**
	 * A constrector that initilaize the Car variables and the superclass "Policy" variables
 	 */
	public Car (int ccregnumbe, int cyear, int cCC, int ppremium, String pname, String padress, int ppsdate, int pd , int pm, int py , int pphone, int pdobd, int pdobm, int pdoby)
	{
		super (pname, padress, ppsdate, pd , pm, py , pphone, pdobd, pdobm, pdoby);
		cregnumber = ccregnumbe;
		year = cyear;
		CC = cCC;
		premium = ppremium;
	}
	/**
	 * Set and get methods that will set and return variabls used in the class
 	 */
	public void setCregnumber (int ccregnumber)
	{
		cregnumber = ccregnumber;
	}

	public int getCregnumber()
	{
		return cregnumber;
	}

	public void setYear (int cyear)
	{
		year = cyear;
	}

	public int getYear ()
	{
		return year;
	}

	public void setCC (int cCC)
	{
		CC = cCC;
	}

	public int getCC ()
	{
		return CC;
	}


	/**
	 * This the abstract method on the Policy class
	 * it calculate the premium of a car
	 * @returns premium
 	 */
	public int CalculatePremium()
	{
		int age;
		age = y - getDoby();

		if (CC <= 1000 && age <= 21)
		{
			premium = 600;
		}

		else if (CC <= 1000 && age > 21)
		{
			premium = 300;
		}

		else if (CC > 1000 && age <= 21)
		{
			premium = 1000;
		}

		else
		{
			premium = 700;
		}
		return premium;
	}

/**
 * returns the policy values
 */
	public String toString()
	  {
	      return (super.toString()  + "\nCar regestration number: " + cregnumber + "\nYear: " + year + "\nCar CC: " + CC);
	  }


}

Sorry for my english ..

Thanx in advance

Are both the class files present in the same "policy" directory? The physical directory structure which holds your .class files needs to reflect your package hierarchy. Read the sticky post at the top of the forum for more information regarding how to run Java programs.

This article has been dead for over six months. Start a new discussion instead.