تبليغاتX
پاکـــفر - جاوا و نوع داده abstract
 

// @author Ali Asadiyan

public abstract class Employee {

private String name;

private Date1 hireDate;

public abstract double getPay();

public final String massege(){

String s ="This Main Writed By Ali Asadiyan";

return s;

}

public Employee(){

name = " ";

hireDate = new Date1("June",05 , 2008);

}

public Employee(String theName, Date1 theDate) {

name = theName;

hireDate = theDate;

}

public Employee(Employee originalObject)

{

name = originalObject.name;

hireDate = originalObject.hireDate;

}

public Date1 getHireDate() {

return hireDate;

}

public void setHireDate(Date1 hireDate) {

this.hireDate = hireDate;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String toString() {

return (name + " " + hireDate.toString());

}

public boolean equals (Employee otherEmployee)

{

return (name == otherEmployee.name) &&

(hireDate.equals(otherEmployee.hireDate));

}

public boolean samePay(Employee other){

return (this.getPay() == other.getPay());

}

}

//Date class

import java.util.Scanner;

public class Date1{

private String month;

private int day;

private int year;

public Date1(String m,int d, int y)

{

day=d;

year=y;

month=m;

}

public Date1(Date1 originalObject){

day = originalObject.day;

year = originalObject.year;

month = originalObject.month;

}

public String toString()

{

return ("in ("+month + " " + day + ", " + year+")");

}

public boolean equals (Date1 otherDate1)

{

return ( (month.equals (otherDate1.month))&&

(day == otherDate1.day) &&

(year == otherDate1.year));

}

public boolean precedes(Date1 otherDate1)

{

return ((yearyear) ||

(year==otherDate1.year && getMonth()

< otherDate1.getMonth()||

(year==otherDate1.year &&

getMonth() == otherDate1.getMonth()&&

dayday)));

}

public void setDate1(int newMonth, int newDay, int newYear)

{

month = monthString(newMonth);

day = newDay;

year = newYear;

}

public String monthString(int monthNumber)

{

switch (monthNumber)

{

case 1: return "Jun.";

case 2: return "Feb.";

case 3: return "Mar.";

case 4: return "Apr.";

case 5: return "May.";

case 6: return "Jun.";

case 7: return "Jul.";

case 8: return "Aug.";

case 9: return "Sep.";

case 10: return "Oct.";

case 11: return "Nov.";

case 12: return "Dec.";

default : System.out.println ("Fatal Error!");

System.exit(0);

return "Error";

}

}

public void writeOutput()

{

System.out.println(month + " " + day + ", " + year);

}

public void readInput()

{

Scanner keyboard = new Scanner(System.in);

System.out.println("Enter month, day & year.");

System.out.println("do not use comma.");

month = keyboard.next();

day = keyboard.nextInt();

year = keyboard.nextInt();

}

public int getDay()

{

return day;

}

public int getYear()

{

return year;

}

public int getMonth()

{

if(month.equalsIgnoreCase ("junuary"))

return 1;

else if(month.equalsIgnoreCase ("february"))

return 2;

else if(month.equalsIgnoreCase ("march"))

return 3;

else if(month.equalsIgnoreCase ("april"))

return 4;

else if(month.equalsIgnoreCase ("may"))

return 5;

else if(month.equalsIgnoreCase ("june"))

return 6;

else if(month.equalsIgnoreCase ("july"))

return 7;

else if(month.equalsIgnoreCase ("august"))

return 8;

else if(month.equalsIgnoreCase ("september"))

return 9;

else if(month.equalsIgnoreCase ("october"))

return 10;

else if(month.equalsIgnoreCase ("november"))

return 11;

else if(month.equalsIgnoreCase ("december"))

return 12;

else

{

System.out.println("Fatal Error");

System.exit (0);

return 0;

}

}

}

//@author Ali Asadiyan

public class SalariedEmployee extends Employee {

private double salary;

public SalariedEmployee(String theName,Date1 theDate,double salary) {

super(theName, theDate);

this.salary = salary;

}

public SalariedEmployee() {

super();

salary=0;

}

public SalariedEmployee(SalariedEmployee originalObject){

super(originalObject);

salary=originalObject.salary;

}

public double getSalary() {

return salary;

}

public void setSalary(double salary) {

this.salary = salary;

}

public boolean equals(SalariedEmployee otherEmployee){

return (salary == otherEmployee.salary)&&

super.equals(otherEmployee);

}

public String toString() {

return super.toString()+"\nemployed and have $"+

salary+" per year";

}

public double getPay () {

System.out.println("monthly salaried Employee HOGHOGH is: ");

return (int)salary/12;

}

}

public class HourlyEmployee extends Employee{

private double wageRate;

private double hours;

public HourlyEmployee() {

super();

wageRate=0;

hours=0;

}

public HourlyEmployee(String theName, Date1 theDate,

double wegRate ,double hours){

super(theName ,theDate);

this.wageRate = wegRate;

this.hours = hours;

}

public HourlyEmployee(HourlyEmployee originalObject){

super(originalObject);

wageRate = originalObject.wageRate;

hours = originalObject.hours;

}

public double getPay(){

return wageRate*hours;

}

public double getHours() {

return hours;

}

public void setHours(double hours) {

this.hours = hours;

}

public double getWageRate() {

return wageRate;

}

public void setWageRate(double wageRate) {

this.wageRate = wageRate;

}

public boolean equals(HourlyEmployee otherEmployee){

return(hours == otherEmployee.hours )&&

(wageRate == otherEmployee.wageRate) &&

super.equals(otherEmployee);

}

public String toString(){

return super.toString() +

"\n $ "+ wageRate+" per hours for " + hours + " hours";

}

}

//class main

// Ali Asadiyan

public class main {

public static void main(String[] args) {

System.out.println("\f SalareidEMPLOYEE & HourlyEMPLOYEE \f"+

"\n \t \f PROGRAM \f\n");

SalariedEmployee salar = new SalariedEmployee();

SalariedEmployee salar2 = new SalariedEmployee();

SalariedEmployee salar3 = new SalariedEmployee();

//***********************************************

HourlyEmployee badbakht1 = new HourlyEmployee();

HourlyEmployee badbakht2 = new HourlyEmployee();

//***********************************************

badbakht1.setName("BIL");

badbakht1.setWageRate(1200);

badbakht1.setHours(55);

badbakht1.toString();

//***********************************************

badbakht2.setName("JACK");

badbakht2.setWageRate(1300);

badbakht2.setHours(66);

badbakht2.toString();

//***********************************************

salar.setName("ali");

salar.setSalary(2500000);

salar.toString();

//***********************************************

salar2.setName("reza");

salar2.setSalary(2600000);

salar2.toString();

//***********************************************

salar3.setName("Akbar");

salar3.setSalary(2000000);

salar3.toString();

//***********************************************

System.out.println(salar.toString()+"\n\n"+

"==============================================\n"+

salar.getName()+" mahianeh = $"+salar.getPay()+

" Hoghogh miGirad \n\n"+

salar2.getName()+" mahianeh = $"+salar2.getPay()+

" Hoghogh miGirad \n\n"+

salar3.getName()+" mahianeh = $"+salar3.getPay()+

" Hoghogh miGirad \n\n"+

"==============================================\n"+

salar2.toString()+"\n"+

salar3.toString()+"\n"+

"==============================================\n"+

"\f Aya "+salar.getName()+" & "+salar2.getName()+

" ba ham barabar hastand? pasokh ==>>\f "

+salar.equals(salar2)+"\n"+

"\f Aya "+salar.getName()+" & "+

salar3.getName()+

" ba ham barabar hastand? pasokh ==>>\f"+

salar.equals(salar3)+"\n"+

"==============================================\n");

System.out.println(badbakht1.toString()+"\n"+

"==============================================\n"+

badbakht1.getName()+" mahianeh = $"+badbakht1.getPay()+

" Hoghogh miGirad \n"+

"==============================================\n"+

badbakht2.toString()+"\n"+

"==============================================\n"+

badbakht2.getName()+" mahianeh = $"

+badbakht2.getPay()+" Hoghogh miGirad \n"+

"==============================================\n"+

"\f aya "+badbakht1.getName()+" ba "+

badbakht2.getName()+" barabarand? pasokh ==>>\f "+

badbakht1.equals(badbakht2)+"\n"+

"==============================================\n"+

"\f aya HOGHOGH "+badbakht1.getName()+" ba "

+badbakht2.getName()+" barabar ast? pasokh ==>>\f "+

badbakht1.samePay(badbakht2)+

"\n============================================\n"+

"\f aya HOGHOGH "+salar.getName()+" ba "

+badbakht1.getName()+" barabar ast? pasokh ==>>\f "

+badbakht1.samePay(badbakht2)+

"\n\f\f\f becuse "+salar.getPay()+" != "

+badbakht1.getPay()+"\f\f\f");

System.out.println("**************************************\n"+

salar.massege());

}

}

نوشته شده توسط علی اسدیان در دوشنبه 18 دی1385 |
مطلب را به بالاترین بفرستید: Balatarin