Për mua do mjaftonte një përshkrim i vogël në Shqip, që të mund të kishin një ide ata që nuk dinë anglisht. Ti e paske përkthyer të gjithën. Shpërblimi im janë 3 klasat që të premtova më lart.
Klasën e katërt është mirë ta bësh vetë, por po të kem kohë do mundohem ta bëj dhe unë.
Kodin e ke të bashkëngjitur në ZIP. U mundova të ndiqja kërkesat e profesorit një për një por nqs ai ka kërkuar diçka specifike, ndryshoje vetë.
Për çdo gjë që nuk kupton mos nguro të pyesësh.
Kodi:
abstract class Employee implements Cloneable {
//======= private ===================
protected String _name;
protected int _id;
//======= public ====================
public Employee(){
_name = "";
_id = 0;
}
public Employee(String name, int id){
_name = name;
_id = id;
}
public Employee(Employee E){
this._name = E._name;
this._id = E._id;
}
public String getName(){
return _name;
}
public int getId(){
return _id;
}
public boolean equals(Object O) {
if( this == O)
return true;
if( !(this.getClass() == O.getClass()) || O == null)
return false;
Employee employee = (Employee) O;
return
this._name.equals(employee._name)
& this._id == employee._id;
}
public String toString(){
return "Name: " + _name + "\nId: " + _id;
}
public Object clone() {
try {
return super.clone();
}
catch (CloneNotSupportedException e) {
throw new InternalError();
}
}
public abstract double getPay();
}
class HourlyEmployee extends Employee implements Cloneable {
//======= private ==============
private int _hours;
private double _rate;
//======= public ===============
public HourlyEmployee(){
super();
_hours = 0;
_rate = 0.0;
}
public HourlyEmployee(String name, int id, int hours, double rate){
super(name, id);
_hours = hours;
_rate = rate;
}
public HourlyEmployee(HourlyEmployee E){
this._hours = E._hours;
this._rate = E._rate;
}
public boolean equals(Object O) {
if( this == O)
return true;
if( !(O instanceof Employee ) || O == null)
return false;
HourlyEmployee hemployee = (HourlyEmployee) O;
return
this._name.equals(hemployee._name)
& this._id == hemployee._id
& this._hours == hemployee._hours
& this._rate == hemployee._rate;
}
public String toString(){
return "Name: " + _name
+ "\nId: " + _id
+ "\nHours:" + _hours
+ "\nRate: " + _rate;
}
public Object clone() {
return super.clone();
}
public double getPay(){
return _hours * _rate;
}
public void display(){
System.out.println("HourlyEmployee-" + _name + "-" + _id + "-" + _hours + "-" + _rate );
}
}
class SalariedEmployee extends Employee implements Cloneable {
//======== private ==============
private int _salary;
//======== public ===============
public SalariedEmployee(){
super();
_salary = 0;
}
public SalariedEmployee(String name, int id, int salary){
super(name, id);
_salary = salary;
}
public SalariedEmployee(SalariedEmployee E){
this._salary = E._salary;
}
public boolean equals(Object O) {
if( this == O)
return true;
if( !(O instanceof Employee ) || O == null)
return false;
SalariedEmployee semployee = (SalariedEmployee) O;
return
this._name.equals(semployee._name)
& this._id == semployee._id
& this._salary == semployee._salary;
}
public String toString(){
return "Name: " + _name
+ "\nId: " + _id
+ "\nSalary:" + _salary;
}
public Object clone() {
return super.clone();
}
public double getPay(){
return _salary / 52.0;
}
public void display(){
System.out.println("SalariedEmployee-" + _name + "-" + _id + "-" + _salary );
}
}
Krijoni Kontakt