السلام عليكم أعضاء المنتدي
أرجو من أعضاء المنتدي الكرام مساعدتي في عمل sorting (فرز حسب قيم المتغيرات) حيث أننى قمت بعمل برنامج صغير شبيهة ببرامج شئون الموظفين وعندما أردت أن أقوم بعمل فرز حسب البيانات الموجودة داخل متغير لم استطيع أن أكمل ذلك
هذا هو البرنامج
public class Employee {
// Employee ID
private int id;
// Employee first name
private String f_name;
// Employee second name
private String s_name;
// Employee last name
private String l_name;
// Employee age
private int age;
// Employee job title
private String job_title;
// Employee salary
private double sal;
// Employee allowance
private double allowance;
// Employee joinning date
private String Join_date;
// Employee annual leave
private int annual_leave;
// Employee sick leave
private int sick_leave;
// default constructor
public Employee() {
String f_name = "None";
String s_name = "None";
String l_name = "None";
int age = 0;
String job_title = "None";
double sal = 0.0;
double allowance = 0.0;
String Join_date = "None";
int annual_leave = 0;
int sick_leave = 0;
}
/* Constructor with parameters
pid : Employee ID parameter
pfn : Employee fname parameter
psn : Employee sname parameter
pln : Employee lname parameter
page : Employee age parameter
pjt : Employee job title parameter
psal : Employee sal parameter
pallowance : Employee allowance parameter
pjd : Employee join_date parameter
pannual : Employee annual_leave parameter
psl : Employee sick_leave parameter
*/
public Employee(int pid, String pfn, String psn, String pln, int page, String pjt, double psal, double pallowance, String pjd, int pannual, int psl) {
this.id = pid;
this.f_name = pfn;
this.s_name = psn;
this.l_name = pln;
this.age = page;
this.job_title = pjt;
this.sal = psal;
this.allowance = pallowance;
this.Join_date = pjd;
this.annual_leave = pannual;
this.sick_leave = psl;
}
/* Constructor with some parameters
This can be used for annual leave
pid : Employee ID parameter
pfn : Employee fname parameter
psn : Employee sname parameter
pln : Employee lname parameter
page : Employee age parameter
pjt : Employee job title parameter
pjd : Employee join_date parameter
pannual : Employee annual_leave parameter
psl : Employee sick_leave parameter
*/
public Employee(int pid, String pfn, String psn, String pln, int page, String pjt, String pjd, int pannual, int psl) {
this.id = pid;
this.f_name = pfn;
this.s_name = psn;
this.l_name = pln;
this.age = page;
this.job_title = pjt;
this.Join_date = pjd;
this.annual_leave = pannual;
this.sick_leave = psl;
}
/* Constructor with some parameters
This can be used for grand salary
pid : Employee ID parameter
pfn : Employee fname parameter
psn : Employee sname parameter
pln : Employee lname parameter
pjt : Employee job title parameter
psal : Employee sal parameter
pallowance : Employee allowance parameter
*/
public Employee(int pid, String pfn, String psn, String pln, String pjt, double psal, double pallowance) {
this.id = pid;
this.f_name = pfn;
this.s_name = psn;
this.l_name = pln;
this.job_title = pjt;
this.sal = psal;
this.allowance = pallowance;
}
// setter method for ID
public void setID(int pid) {
this.id = pid;
}
// getter method for ID
// This method can get the value of ID variable or we can say this method can return the value of ID variable
// return id
public int getID() {
return this.id;
}
// setter method for fname
public void setFname(String pfname) {
this.f_name = pfname;
}
// getter method for fname
// return fname
public String getFname() {
return this.f_name;
}
// setter method for sname
public void setSname(String psname) {
this.s_name = psname;
}
// getter for sname
// return sname
public String getSname() {
return this.s_name;
}
// setter method for lname
public void setLname(String plname) {
this.l_name = plname;
}
// getter method for lname
// return lname
public String getLname() {
return this.l_name;
}
// setter mthod for age
public void setAge(int page) {
this.age = page;
}
// getter method for age
// return age
public int getAge() {
return this.age;
}
// setter method for job title
public void setJobTitle(String pjt) {
this.job_title = pjt;
}
// getter method for job title
// return job title
public String getJobTitle() {
return this.job_title;
}
// setter method for salary
public void setSalary(double psal) {
this.sal = psal;
}
// getter method for salary
// return sal
public double getSal() {
return this.sal;
}
// setter method for allowance
public void setAllowance(double pallowance) {
this.allowance = pallowance;
}
// getter method for allowance
// return allowance
public double getAllowance() {
return this.allowance;
}
// setter method for joinning date
public void setJDate(String pjd) {
this.Join_date = pjd;
}
// getter method for join_date
// return join date
public String getJoinDate() {
return this.Join_date;
}
// setter method for annual leave
public void setAnnualLeave(int pal) {
this.annual_leave = pal;
}
// getter method for annual leave
// return annual leave
public int getAnnualLeave() {
return this.annual_leave;
}
// settter method for sick leave
public void setSickLeave(int psl) {
this.sick_leave = psl;
}
// getter method for sick leave
// return sick leave
public int getSickLeave() {
return this.sick_leave;
}
// Creat method to print all attributies
public void printEmployeeInformation() {
System.out.println("------------------ (" + this.id + ")" + this.f_name + " " + this.s_name + " " + this.l_name + " Information --------------");
System.out.println("Employee Age : " + this.age);
System.out.println("Employee Job Title : " + this.job_title);
System.out.println("Employee Salary : " + this.sal);
System.out.println("Employee Allowance : " + this.allowance);
System.out.println("Employee Joinning Date : "+ this.Join_date);
System.out.println("Employee Annual Leave : "+this.annual_leave);
System.out.println("Employee Sick Leave : "+this.sick_leave);
}
}
// Creat method to print Employee Annual Leave
public void PrintEmployeeAnuualLeave() {
System.out.println("------------------ (" + this.id + ")" + this.f_name + " " + this.s_name + " " + this.l_name + " Information --------------");
System.out.println("Employee Annual Leave : " + this.annual_leave);
}
// Creat method to print Employee Sick Leave
public void PrintEmplyeeSickLeave() {
System.out.println("------------------ (" + this.id + ")" + this.f_name + " " + this.s_name + " " + this.l_name + " Information --------------");
System.out.println("Employee Sick Leave : "+this.sick_leave);
}
}
***********************************************************************************************
/*
* @author Waleed Oraby
*/
public class Main {
public static void main (String[]args){
Employee diab = new Employee(100,"Diab","Jaber","Jaber",33,"HR",450,30,"01-Feb.-2009",30,5);
Employee dawoud = new Employee(55,"Dawoud","Al Khateeb","Al Khateeb",39,"HR",1000,50,"01-Mar.-2000",40,6);
Employee khaled = new Employee(205,"Khaled","Khaled","Khaled",38,"HR",500,20,"01-Feb.-2003",23,7);
Employee gopi = new Employee(300,"Gopi","Chilakuri","Chilakuri",35,"Accounts",750,30,"01-Jan.-2010",55,3);
Employee sulieman = new Employee(12,"Sulieman","Jaber","Jaber",45,"Logistics",800,30,"01-Nov.-2000",20,8);
Employee basil = new Employee(315,"Basil","Hertani","Hertani",23,"Sales",550,30,"01-Jan.-2013",15,4);
Employee mshanti = new Employee(312,"Mohamed","Shanti","Shanti",34,"Sales",650,30,"01-Oct.-2013",34,2);
Employee elsie = new Employee(99,"Elsie","S'Silva","D'Silva",50,"Qoutation",1000,30,"01-Sep.-1999",66,2);
Employee salim = new Employee(155,"Salim","Sherfan","Sherfan",48,"Development Projects",1600,30,"01-Feb.-2009",10,10);
Employee lidya = new Employee(244,"Lidya","Fernandes","Fernandes",38,"Secretary",500,30,"01-Jun.-2004",50,12);
Employee samuel = new Employee(225,"Samuel","James","James",44,"Managing Projects",1500,30,"01-Jul.-2000",40,3);
Employee kareem = new Employee(298,"Kareem","Kareem","Kareem",49,"Elec. Engineer",500,30,"01-Dec.-2011",22,5);
Employee msager = new Employee(1,"Mohamed","Al Sager","Al Sager",40,"Executive Manager",2000,30,"01-Jan.-1995",28,5);
Employee ashour = new Employee(77,"Ashour","Jaber","Jaber",42,"Logistics",400,30,"01-Feb.-2000",15,8);
Employee waleed = new Employee(305,"Waleed","Refaat","Oraby",34,"HR",350,0,"27-Dec.-2011",20,4);
// print Employee Info
diab.printEmployeeInformation();
dawoud.printEmployeeInformation();
khaled.printEmployeeInformation();
gopi.printEmployeeInformation();
sulieman.printEmployeeInformation();
basil.printEmployeeInformation();
mshanti.printEmployeeInformation();
elsie.printEmployeeInformation();
salim.printEmployeeInformation();
lidya.printEmployeeInformation();
samuel.printEmployeeInformation();
kareem.printEmployeeInformation();
msager.printEmployeeInformation();
ashour.printEmployeeInformation();
waleed.printEmployeeInformation();
}
}
سؤالي هو :
كيف يمكنني أن أقوم بعمل فرز حسب القيم الموجودة في المتغير id حيث يقوم بطباعة بيانات الموظفين طبقاً للـ id الأقل فالأكبر
وشكرا