java inheritance 2nd class

August 5, 2008

public class ParttimeEmployee extends Employee {
	private int num_hours;
	private double cum_salary;

ParttimeEmployee(String name,char gender,int num_hours){
	super(name,gender);
	this.num_hours=num_hours;
	this.cum_salary=((num_hours-100)* 500 )+ 100*300;
}
	void Display(){
		super.display();
		System.out.print("No _of_Hours worked 	  : "+ num_hours);
		System.out.print("\nSalary of Employee        : "+cum_salary);
		System.out.println("\n");
	}

}

java inheritance

August 5, 2008
public class FulltimeEmployee extends Employee {
	private char rank;
	private  double salary;

	FulltimeEmployee(String name,char gender,char rank){
		super(name,gender);
		this.rank=rank;

		if ((rank=='s') || (rank=='S'))
			salary=20000.00;
		else
			salary=30000.00;
	}
	public void display(){
		super.display();
		String strRank=(rank =='S' ? "Senior"         : "Junior");
		System.out.println("Rank of Employee          : "+strRank);
		System.out.println("The Salary of Employee is : "+salary);
		System.out.println();
	}
}

Type of Employee with java using inheritance n dynamic arrays

August 5, 2008
public class Employee {
	private String name;
	private char gender;

	 Employee(String name,char gender){
		this.name=name;
		this.gender=gender;

	}
	void display(){
			System.out.print("Name of Employee is       : "+name);
			String strGender =(gender=='f' ? "Female" : "Male");
			System.out.println("\nGender of Employee        : "+strGender);
		}
}

Fun with some Java Codes yeah i know its too basic

August 5, 2008

import java.io.*;
public class CreateEmployees {

	public static void main(String [] args)throws IOException{

		BufferedReader br= new BufferedReader(new InputStreamReader(System.in));

		String str;
		String strname;
		char gender='m';
		char rank='s';
		int numemp,numempfull,numemppart,numhours;
		boolean goodname;

		System.out.print("Enter Number of employees :\t");
			str=br.readLine();
			numemp=Integer.parseInt(str); 													//casting a datatype
			if(numemp<=0){
				System.err.println("Invalid Number of  Employees");
				System.exit(1);
			}

		System.out.print("Enter the Number of Employees who are Fulltime:\t ");
			str=br.readLine();
			numempfull=Integer.parseInt(str);

			if ((numempfullnumemp)){
				System.err.println("Invalid Number of fulltime Employees");
				System.exit(1);
			}

			//all validation dones so we will declare dynamic arrays now;
			numemppart=numemp-numempfull;  													//no_ of partimers

																							//using dynamic array

			FulltimeEmployee fullemp[]=new FulltimeEmployee[numempfull];
			ParttimeEmployee partemp[]=new ParttimeEmployee[numemppart];

			for(int i=0;i<numempfull;i++){ 													//fulltimers

				System.out.print("Enter name of Employee "+ (i+1)+"       : \t");
					str=br.readLine();
					strname=str;

					goodname=checkstr(strname);

						if ((strname.length()<=0) || (!goodname)){                          //advance check for name
							System.err.println("Invalid name for Employee");
							System.exit(1);
						}//if	

					strname=strname.toUpperCase(); 											//converting to uppercase

				System.out.print("Enter the gender of Employee "+ (i+1)+" : \t");
					str=br.readLine();

					boolean s=(str.equalsIgnoreCase("m")  || str.equalsIgnoreCase("f"));

					if (!s){  																//error checking mechanism
						System.err.println("Invalid Gender");
						System.exit(1);
					}
					else if (str.equalsIgnoreCase("m"))
						gender='m';
					else
						gender='f';

 				System.out.print("Enter Rank  of Employee "+(i+1)+"       :\t");
 					str=br.readLine();
	 				boolean r=(str.equalsIgnoreCase("s")  || str.equalsIgnoreCase("j"));

					if (!r){
						System.err.println("Invalid Rank");
						System.exit(1);
					}
					else if (str.equalsIgnoreCase("s"))
						rank='s';
					else
						rank='j';

					fullemp[i] = new FulltimeEmployee(strname,gender,rank); 					//assigning values to object full emp i
					System.out.println();

			}//for i

			System.out.println("Enter Details for parttimers : \n");

			for(int j=0;j<numemppart;j++){

				System.out.print("Enter name of Employee "+ (j+1)+"                     : \t");
				str=br.readLine();
				strname=str;

				goodname=checkstr(strname);

				if ((strname.length()<=0) || (!goodname)){
					System.err.println("Invalid name for Employee");
					System.exit(1);
				}//if	

				strname=strname.toUpperCase();

				System.out.print("Enter the gender of Employee "+ (j+1)+"               : \t");
				str=br.readLine();

				boolean s=(str.equalsIgnoreCase("m")  || str.equalsIgnoreCase("f"));

				if (!s){
					System.err.println("Invalid Gender");
					System.exit(1);
				}
				else if (str.equalsIgnoreCase("m"))
					gender='m';
				else
					gender='f';

				System.out.print("Enter Number of Hours worked by employee  "+(j+1)+ " : ");
				str=br.readLine();
				numhours=Integer.parseInt(str);

				if (numhours<=0){
					System.err.println("Invalid No of hours");
					System.exit(1);
				}
				partemp[j]=new ParttimeEmployee(strname,gender,numhours);
				System.out.println();
			}//for j

		System.out.println("Here are the Details for full time employees    : \n");
		for(int k=0;k<numempfull;k++){
			fullemp[k].display();
			System.out.println("\n");
		}

		System.out.println("Here are the Details for Parttime time employees : \n");
		for(int l=0;l=0 && validated){

			for(int j=invalidstr.length()-1;j>=0;j--){
				if (str.charAt(i)==invalidstr.charAt(j))
				   return validated=false;

			}//j
			i--;
		}//while

		return validated;
	}
}