Have been trying to learn from some old documentation that I bought several years ago but did not persevere with!
Have Person class which compiles ok. The Employee class cannot find Person class in the extend statement, the BigCorp cannot find either the Person or Employee classes. All files are saved and compied in c:\LMSJava\BigCorp\
Can anyone help as I have come to a grinding halt.
Thanks in anticipation.
///////////////////////////////////////////////
package BigCorp;
import java.io.*;
public class BigCorp
{
public static void main (String args[])
{
//** Create Person Object p1
Person p1=new Person();
p1.setFname=("Joseph");
p1.setLName=("Annan");
p1.setHeight(2);
p1.walk();
p1.talk();
//** Create Person Object p2
Person p2=new Person();
p2.setFname=("Tony");
p2.setLName=("Blair");
p2.setHeight(3);
p2.walk();
p2.talk();
p1=null;
p2=null;
//** Create Employee Object e1
Employee e1=new Employee();
e1.setFName("Sven");
e1.setLName("Erikson");
e1.setID("0001");
e1.pay();
e1.talk();
e1.walk();
//** Create Employee Object e2
Employee e2=new Employee();
e2.setFName("Michael");
e2.setLName("Kackson");
e2.setID("0002");
e2.pay();
e2.talk();
e2.walk();
e1=null;
e2=null;
}
}
/////////////////////////////////////////////
package BigCorp;
import java.io.*;
public abstract class Person
{
String lName=""; //instance variable
String fName=""; //instance variable
int height=0; //integer variable
static long population=0; //static variable
static long totalHeight=0; //static variable
static float averageHeight=0; //static variable
private boolean delete=false; //boolean variable
//**
public Person() //Constructor to increase variable population by 1
{
++population; // Add 1
}
//**
public Person(String fName, String lName)
{
this();
this.fName=fName;
this.lName=lName;
}
//**
public void setFName(String firstName)
{
fName=firstName; //Method to set first name
}
//**
public String getFName()
{
return fName; //Method to get first name
}
//**
public void setLName(String lastName)
{
lName=lastName; //Method to set last name
}
//**
public String getLName()
{
return lName; //Method to get first name
}
//**
public String getName()
{
return fName+" "+lName; //Method to combine first and last names
}
//**
public static long getPopulation()
{
return population; //Method to get population
}
//**
public void setHeight(int height) //Method to set height of population
{
this.height=height;
adjustAverageHeight(height);
}
//**
public int getHeight() //Method returns height of individual
{
return height;
}
//**
public static float getAverageHeight() //Method returns average hight of population
{
return averageHeight;
}
//**
public void adjustAverageHeight(int heightIncrement)
{
if(delete) totalHeight-=heightIncrement; //Removes current height from population
else totalHeight+=(heightIncrement-this.height);
if(population==0) averageHeight=0.0f;
else averageHeight=(float)totalHeight/population; //Calculates running average
}
//**
public void walk() //Combines first and last names
{
// System.out.println(this.fName()+" "+this.lName()+" is walking.");
}
//**
public void talk() //Combines first and last names
{
// System.out.println(this.fName()+" "+this.lName()+" is talking.");
}
//**
public void talk(String message) //Reuses - overloads talk method
{
// System.out.println(this.getFName()+""+this.getLName()+" says: "+message);
}
//**
public void finalize()
{
delete=true;
--population;
System.out.println("Reduced height: "+getLName()+" "+getHeight());
adjustAverageHeight(this.getHeight());
}
}
////////////////////////////////////////////////////////////////
package BigCorp;
public class Employee extends Person
{
String ID="";
double wallet=0.0;
//**
public Employee()
{
}
//**
public Employee(String firstName, String surname, String id) //Constructor
{
super(firstName,surname);
this.ID=id;
}
//**
public void setID(String id)
{
ID=id;
}
//**
public String getID()
{
return ID;
}
//**
public double getWallet()
{
return wallet;
}
//
public void pay()
{
// System.out.println(this.getName()+" was paid");
}
}