This is super class of all,Employee class.
import java.util.Scanner;
import java.util.Calendar;
import java.util.*;
class Employee {
Scanner in = new Scanner(System.in);
Calendar cal = Calendar.getInstance();
String name;
String number;
int month;
int week;
double pay;
void load() {
System.out.println("Enter name of employee");
name = in.nextLine();
System.out.println("Enter social security number");
number = in.nextLine();
System.out.println("Enter employee's birthday month(1-12)");
month = in.nextInt();
System.out.println("Enter employee's birthday week(1-4)");
week = in.nextInt();
}
public String toString() {
return "employee : " + name + " social security number : " + number
+ " paycheck : $" + pay;
}
void getBonus() {
int mont = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DAY_OF_MONTH);
if (month == mont + 1 && week == (day / 7) + 1)
pay = pay + 100;
}
}
This is subclass of employee .
import java.util.Scanner;
class Hourly extends Employee {
Scanner in = new Scanner(System.in);
double pay;
int hpay;
int hours;
void load() {
System.out.println("Enter hourly pay");
hpay = in.nextInt();
System.out.println("Enter no. of hours worked last week");
hours = in.nextInt();
}
double getEarnings() {
if (hours > 40)
pay = 1.5 * (hours - 40) * hpay + hpay * 40;
else
pay = hpay * hours;
return pay;
}
}
There are 2 more subclasses like these and finally i have test file.
import java.util.Scanner;
class driver {
public static void main(String args[]) {
int i;
Scanner in = new Scanner(System.in);
System.out.println("Enter no. of employees");
int a = in.nextInt();
for (i = 1; i <= a; i++) {
System.out
.println("Enter type : Hourly(1),Salaried(2),Salaried plus commision(3)");
int b = in.nextInt();
if (b == 1) {
Hourly h = new Hourly();
h.super.load();// error cannot find symbol h
h.load();
h.getEarnings();
}
if (b == 2) {
Salaried s = new Salaried();
s.load();
s.getEarnings();
}
if (b == 3) {
Salariedpluscommision sp = new Salariedpluscommision();
sp.super();// error that super should be in first line but then
// where can i define sp
sp.super.load();// cannot find symbol sp
sp.load();
sp.getEarnings();
}
}
}
}
I have got 3 errors in these codes and as i am beginner i don't know how can i solve these errors. My program takes the employee's details from user and calculate paycheck of that employee. Also,I am confused in how can i print all employee's paychecks at last after user have completed giving input of all employee's details.Can i do these with an array ? But first,i have to remove these errors and also suggest my which topics are weak which i should focus more.
Thank you in advance