hi
I m working on this assignment...base class employee sub class staff .now i have to Create a StaffDriver Java program that:

a. creates two staff objects
b. prompts the user to enter name, id, hours and rate
for each object
c. compute the pay for each object
d. displays employee information
please help me so far i have this code....
thanks

import java.io.IOException;


public class employee {
private String Name;
private int Id;

public static void main (String args[]) throws IOException {
	//BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	//System.out.println("Please input a name and press Enter ");
	//String Name = in.readLine();
	//System.out.println("Please input an Id and press Enter ");
	//Integer Id = Integer.parseInt(in.readLine());
	//System.out.println("You entered " + Name + " id: " + Id);

}

public employee()
{
	 setName("Any Employees");
	 Id = 9999;
}
public  void GetEmployee( String NameIn,int IdIn )
{
	 setName(NameIn);
	 Id = IdIn;
}
public void setName(String name) {
	Name = name;
}

public String getName() {
	return Name;
}

public  void ShowEmployee()
{
	System.out.println( getName() + " " + Id);
}
public void ZapEmployee()
{
	System.out.println( getName() +  " No Longer works here");
	setName("Former Employee");
		Id = 9999;
}
}



public class Staff extends employee
{
	private double Hours;
	private double Rate;
	private double Pay;
	public Staff()
	{
		Hours = 0;
		Rate = 0;
		Pay =  0;
			
	}
	public void GetEmployee(String NameIn, int IdIn, double HoursIn, double RateIn)			
	
	{
		super.GetEmployee(NameIn, IdIn);
		Hours = HoursIn;
		Rate = RateIn;
		}
	public void ShowEmployee()
	{
		super.ShowEmployee();
		System.out.println( Pay + " ");				
	}
	public void ComputePay()
	{
	if (Hours > 40)
		{
			Pay = (40 * Rate) + ((Hours - 40)* (1.5 * Rate));
		}
		
	else
	{
				Pay = Hours * Rate;
	}
	
	System.out.println(getName() + " " + Pay);
	}	


}
Staff staff1 = new Staff();
// and call its methods to set the name and the other values. Then call its other methods to display it.

Doesn't this code works?

try {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please input a name and press Enter ");
String Name = in.readLine();
System.out.println("Please input an Id and press Enter ");
Integer Id = Integer.parseInt(in.readLine());
System.out.println("You entered " + Name + " id: " + Id);

Staff staff1 = new Staff();
staff1.GetEmployee(Name, Id);
staff1.ShowEmployee();
staff1.ComputePay();
} catch (Exception e) {
  e.printStackTrace();
}

All you have to do is read the other values as well.

public static void main(String[] args){
		Staff staff1 = new Staff();
		Scanner in = new Scanner(System.in);
		String name = null;
		int id = 0;
		double hour = 0;
		int rate = 0;

		System.out.println("enter employee name");
		if(in.hasNext())
			name = in.next();

		System.out.println("enter employee id");
		if(in.hasNextInt())
			id = in.nextInt();

		System.out.println("enter employee hour");
		if(in.hasNextDouble())
			hour = in.nextDouble();

		System.out.println("enter empolyee rate");
		if(in.hasNextInt())
			rate = in.nextInt();

		System.out.println("enter employee hours");
		staff1.GetEmployee(name, id, hour, rate);

                System.out.println(staff1.ComputePay); // prints the pay
		System.out.println(staff1.getName()); // prints out the information. you need more getter methods

it is dangerous to parsing here ...if user enter incorrect data..exception will be thrown.. so i would do it this way for safe.

also, you need other getter method for id, hour and rate.
when u trying to set something like getEmpolyee.. use the word set, it is confusing to "get" when your not getting it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.