OK so I have this homework assignment for a java class that I am taking. with the exception of a couple things not working right(search, delete) ive pretty much got it. The problem I am having now is that I need to implement a controlled break so that my report prints correctly (all Hourly Employees together under one heading, the same for a Salaried Employee and a Piece Work Employee) I am posting all my code for all my classes...any help you could give me would be really appreciated. Thanks a lot.

this is my App Driver. I'm either not sure how to write the test in the app driver for search and delete, or if they are written wrong in the container class.

public class AppDriver {
	
	public static void main(String[] args) {



Employee e0 = new Hourly("John","Doe",40.00,15.50);
System.out.println(e0.toString());
Employee e1 = new Hourly();
System.out.println(e1.toString());
Employee e2 = new Salaried("Jane","Drumington",100000.00);
System.out.println(e2.toString());
Employee e3 = new PieceWork("Ron","Howard",100.00,.26);
System.out.println(e3.toString());

Employees.add(new Hourly("Marion","Louise",13.00,40.00));
Employees.add(new Salaried("Davidson","Carl",150000.00));
Employees.add(new PieceWork("Whittle","Ed",11.50,25.50));
Employees.add(new Salaried("Doe","John",258550.00));
Employees.add(new PieceWork("Prentiss", "Paula",15.75,50.50));



for (int i=0; i<Employees.emps.length;i++){
	if(EmployeeRecord.empType == 'h' && Employees.emps[i] != null){
			System.out.println(Employees.emps[i]);
			}
			}
for (int i=0; i<Employees.emps.length;i++){
	if(EmployeeRecord.empType == 'p' && Employees.emps[i] != null){
			System.out.println(Employees.emps[i]);
			}
			}
for (int i=0; i<Employees.emps.length;i++){
	 if(EmployeeRecord.empType == 's' && Employees.emps[i] != null){
			System.out.println(Employees.emps[i]);
			}
			}
}

	}

this is my Employee Class. its pretty self explanatory this one. and i'm pretty sure i have everything working in this class.

import java.util.*;

//Thomas Land
//CISP401
//Assignment 2b

public abstract class Employee implements Comparable<Employee>{
 
		protected EmployeeRecord empRec;


public Employee(){
	this.setEmpRec(new EmployeeRecord());
		calcGross();
		calcTax();
		calcNet();
}

public Employee(String ln, String fn,char eT){
	this.setEmpRec(new EmployeeRecord(ln,fn,eT));
	calcGross();
	calcTax();
	calcNet();
}
public Employee(Employee e){
this.setEmpRec(new EmployeeRecord(e.getEmpRec()));
calcGross();
calcTax();
calcNet();
}

public Employee(EmployeeRecord eR){
	this.setEmpRec(new EmployeeRecord(eR));
	calcGross();
	calcTax();
	calcNet();
}
public int compareTo(Employee other) {
return (""+empRec.empType+ empRec.lastName + empRec.firstName).compareTo(""+other.getEmpRec().empType+ other.getEmpRec().lastName + other.getEmpRec().firstName);
}
//Setter Methods
public abstract void calcGross();

public void calcTax(){
this.getEmpRec();
	this.empRec.tax = this.empRec.gross * 0.15;
}

public void calcNet(){
this.getEmpRec();
	this.empRec.net = this.empRec.gross - this.empRec.tax;
}
public void setEmpRec(EmployeeRecord empRec) {
	this.empRec = empRec;
}
// Getter methods
public double getGross(){
this.getEmpRec();
return this.empRec.gross;
}
public double getTax(){
this.getEmpRec();
return this.empRec.tax;
}
public double getNet(){
this.getEmpRec();
return this.empRec.net;
}
public EmployeeRecord getEmpRec() {
	return new EmployeeRecord(this.empRec);
}

//to String Method
public String toString(){
		
	this.getEmpRec();
	System.out.println("      Name              PayRate      HrsWrkd        Gross          Tax          Net");

		return String.format("%-15s %13.2f %13.2f %13.2f\n", this.empRec.fullName, this.empRec.gross, this.empRec.tax, this.empRec.net);
		
	}

public String getLastName() {
	getEmpRec();
	return empRec.lastName;
}

public String getFirstName() {
	getEmpRec();
	return empRec.firstName;
}

public void setLastName(String ln) {
	getEmpRec();
	empRec.lastName = ln;
}

public void setFirstName(String fn) {
	getEmpRec();
	empRec.firstName = fn;
}	
}

This is the Employee Record class, i think it does the job its meant to, but mabey it needs some more work, or some more methods...

public class EmployeeRecord implements Comparable<Employee>{
    public  String lastName, firstName;
 	public double gross,tax,net;
		public String fullName;
   public static char empType;
	public EmployeeRecord(){
	this.lastName = null;
	this.firstName = null;
	
	}

	public EmployeeRecord(String ln,String fn,char eT){
		this.firstName = fn;
		this.lastName = ln;
		this.fullName = this.lastName +", "+ this.firstName;
		EmployeeRecord.empType = eT;
	}

	public EmployeeRecord(EmployeeRecord e){
	this.firstName = e.firstName;
	this.lastName = e.lastName;
	this.fullName = e.fullName;
	EmployeeRecord.empType = e.empType;
	}
	public int compareTo(EmployeeRecord other) {
		return (""+empType+ lastName + firstName).compareTo(""+EmployeeRecord.empType+ other.lastName + other.firstName);
		}
		public String toString(){
		
		return String.format("%-15s %13.2f %13.2f %13.2f\n", fullName, gross, tax, net);
		
	}

		@Override
		public int compareTo(Employee arg0) {
			return 0;
		}	


	}

this is the Employees Class...this is the container class, this is where im pretty sure everything that is wrong is because of here(search, delete) and apparently this is also the class where im supposed to put the key for the controlled break key should be empType + lastName. however i have no idea how to implement the controlled break or the key...

import java.util.*;

public class Employees{
private static String lastName;
private static String firstName;
static Employee empRef;
Employee tmp;
private static int maxRecord = 100;
private static int recSize = 0;
private static int noEmp=0;
private static int foundRec=0;

public static Employee[] emps = new Employee[maxRecord];

public Employees(){
lastName = null;
firstName = null;
}

public Employees(String ln, String fn){
lastName = ln;
firstName = fn;
}

public Employees (Employee e){
empRef = e;
}

public Employees(Employees anotherEmp){
Employees empRef = anotherEmp;
}
// Accessor Methods
public Employee get(int i){
return emps[i];
}

// Mutator Methods
public static void add(Employee e){
if(e != null) 
	empRef = e;
for(int i = 0; i < maxRecord; i++){
	if (emps[i] == null){
		emps[i] = empRef;
recSize = i+1;
break;
  }
 }
}

public static void delete(String ln, String fn){
if (ln != null)
	lastName = ln;
else lastName = null;
if (fn != null)
firstName = fn;
else firstName = null;
foundRec = 0;
for (int i = 0; i <=recSize; i++){
if (emps[i]== null){
foundRec = i;
break; 
}
if (lastName == emps[i].getLastName() && firstName == emps[i].getFirstName()) 
emps[i].setLastName("#");
emps[i].setFirstName("#");

   }
}


//Search
public static int search(String ln, String fn){
boolean found = false;
lastName = ln;
firstName = fn;
foundRec = 0;

for(int i = 0; i<=recSize; i++){
if(emps[i] == null){
foundRec = 0;
found = false;
break;
}
if (lastName == emps[i].getLastName() && firstName == emps[i].getFirstName()){
foundRec = i;
found = true;
break;
}
}
return foundRec;
}
//iterator
public static void iterate(){
for(int i = 0; i<=recSize; i++){
	if (emps[i] == null){
	emps[i] = empRef;
	foundRec = i;
	break;
	}
	if (emps[i].getLastName() != "#")
		noEmp = noEmp + 1;
	}
}
//Returns array size on employee container
public int recSize(){foundRec = 0;
recSize = 1;
int i=0;
while(i <= maxRecord){
	if (emps[i] == null){
		foundRec = i;
		break;
	}
	i++;
} 
recSize = i-1;
return recSize;
	}
public int empCount(){
	for (int i = 0; i<=maxRecord;i++){
		if (emps[i] == null) break;
		if (emps[i].getLastName() != "#")
			noEmp = noEmp +1;
	}
	return noEmp;
}
//sort container
public void sort(){
	int size = 0;
	Employee tmp = null;
	for (int y = recSize -1;y>1;y--){
		for (int x = 0; x < y; x++){
			if (emps[x+1].getEmpRec().compareTo(emps[x].getEmpRec())<0)
				tmp = emps[x];
			emps[x] = emps[x+1];
			emps[x+1] = tmp;
		}
	}
}

}

this is the Hourly class

public class Hourly extends Employee{
	private double hrsWrkd, payRate;

// Constructors
	public Hourly(){
    super();
	this.hrsWrkd = 0.0;
	this.payRate = 0.0;
	}
	public Hourly(String ln, String fn,double hw, double pr){
	super(ln,fn,'h');
	this.hrsWrkd = hw;
	this.payRate = pr;
	calcGross();
	super.calcTax();
	super.calcNet();
	} 
	//Mutators
	public void calcGross(){
	this.getEmpRec();
	this.empRec.gross = this.payRate * this.hrsWrkd;
	}
	
	public void setEmpRec(EmployeeRecord empRec) {
		this.empRec = empRec;
	}
	public void setHours(){
	this.getEmpRec();
	this.hrsWrkd = hrsWrkd;
	}
	public void setRate(){
	this.getEmpRec();
	this.payRate = payRate;
	}
	
	//Accessors
	public EmployeeRecord getEmpRec() {
		return new EmployeeRecord(this.empRec);
	}
	public double getHours(){
	this.getEmpRec();
	return hrsWrkd;
	}
	public double getRate(){
	this.getEmpRec();
	return payRate;
	}

	//to String Method
	public String toString(){
			
		this.getEmpRec();
			System.out.println("      Name              PayRate      HrsWrkd        Gross          Tax          Net");
			return String.format("%-15s %13.2f %13.2f %13.2f %13.2f %13.2f\n", this.empRec.fullName, this.payRate, this.hrsWrkd,this.empRec.gross, this.empRec.tax, this.empRec.net);
			
		}
	}

this is the piecework class

public class PieceWork extends Employee{
	private double numPieces, payPerPiece;
	
	//Constructors
	public PieceWork(){
		super();
		this.numPieces = 0;
		this.payPerPiece = 0.0;
	}
	public PieceWork(String ln, String fn, double np, double ppp){
		super(ln,fn,'p');
		this.numPieces = np;
		this.payPerPiece = ppp;
		calcGross();
		super.calcTax();
		super.calcNet();		
	}
	//Mutators
	public void calcGross(){
	this.getEmpRec();
	this.empRec.gross = this.numPieces * this.payPerPiece;
	}
	//Accessors
	public EmployeeRecord getEmpRec() {
		return new EmployeeRecord(this.empRec);
	}
	//to String Method
	public String toString(){
			
		this.getEmpRec();
		System.out.println("      Name             numPieces      payPerPiece   Gross          Tax          Net");
			return String.format("%-15s %13.2f %13.2f %13.2f %13.2f %13.2f\n", this.empRec.fullName, this.numPieces, this.payPerPiece,this.empRec.gross, this.empRec.tax, this.empRec.net);
			
		}

	}

and Finally the Salaried Class

public class Salaried extends Employee{
	private double salary;

//Constructors
	public Salaried(){
	super();
	this.salary = 0.0;
	calcGross();
	super.calcTax();
	super.calcNet();
	}

	public Salaried(String ln,String fn,double s){
	super(ln,fn,'s');
	salary = s;
	
	calcGross();
	super.calcTax();
	super.calcNet();
	}
	//Accessors
	public void calcGross(){
	this.getEmpRec();
	this.empRec.gross = this.salary;
	}
	//Mutators
	public EmployeeRecord getEmpRec() {
		return new EmployeeRecord(this.empRec);
	}
	
	public void setSalary(double s){
	salary = s;
	}
	//to String Method
	public String toString(){
			
		this.getEmpRec();
		System.out.println("      Name              Salary        Gross          Tax          Net");

			return String.format("%-15s %13.2f %13.2f %13.2f %13.2f\n", this.empRec.fullName, this.salary,this.empRec.gross, this.empRec.tax, this.empRec.net);
			
		}
	}

Hey man that's a lot of code for just one question. Without reading it I can tell you break is a sign of bad program design. Your code needs to be re-thought. Could you break your code down a bit and make it take less time to read?

well that may be true, but that is what the assignment calls for, adding a key in the container class and adding a controlled break in the app driver to produce to report, child classes grouped together under one header for each child class.

Hey man that's a lot of code for just one question. Without reading it I can tell you break is a sign of bad program design. Your code needs to be re-thought. Could you break your code down a bit and make it take less time to read?

and i know that is a lot of code...i just put the whole thing up here. the main place i need help with is in my container class called the Employees class. im pretty sure everything i need help with is there and the app driver....thanks a lot
Thomas

well that may be true, but that is what the assignment calls for, adding a key in the container class and adding a controlled break in the app driver to produce to report, child classes grouped together under one header for each child class.

Tell me if this is what you're looking for:
null compared to Employee object data in Employees.delete()
boolean Employees.search().found unused
Employees.delete does not garbagize Employee object

Employees emps(new Employee(bla));
(emps.get(search("lastName", "firstName")).getFirstName() == "firstName") [B]is true[/B]
emps.delete("lastName", firstName") [B]sets record entry for last name to "#"[/B]
This article has been dead for over six months. Start a new discussion instead.