الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

ساعدوني في عمل هذا البرنامج

مغلق
بدأه نيو هنا في 27 ديسمبر 2011 · 9 رد · 667 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

عندي اختبار الاسبوع الجاي وعندي استفسار عن طريقة عمل هذا البرنامج بالجافا

372878.jpg

#2
نيو هنا كتب:

السلام عليكم

عندي اختبار الاسبوع الجاي وعندي استفسار عن طريقة عمل هذا البرنامج بالجافا

372878.jpg

السلام عليكم

اعتقد انك بي 32 مشاركة لست جديد في المنتدى

و على ما اضن ان حل الواجبات مخالف لقوانين المنتدى

بلاضافة الى كتابة السوال بي الاجنبية

و العنوان غير مناسب ايضا

تم تعديل هذه المشاركة بواسطة sahraoui17 في 27 ديسمبر 2011 في 21:12

#3

اخوي انا جديده على البرنامج

وهذا سؤال من اوراق سابقة ليس بواجب

تحياتي

#4
نيو هنا كتب:

اخوي انا جديده على البرنامج

وهذا سؤال من اوراق سابقة ليس بواجب

تحياتي

السلام عليكم

يجب ان تعطى محاولتك

#5
// name of class

public class TwoD_Array{

/**main method */

public static void main(String[] args){

//creat 2D arrray and enter elements

int[ ][ ]b={{2,4,3,4,5,8,8},

{7,3,4,3,3,4,4},

{3,3,4,3,3,2,2},{9,3,4,7,3,4,1},

{3,5,4,3,6,3,8},{3,4,4,6,3,4,4,},

{3,7,4,8,3,8,4},{6,3,5,9,2,7,9}};

//create another array to put sum in one column

int []y=new int[8];

//use for loop to collect hours for each emloyees

for (int row = 0; row <b.length; row++){

int sum = 0;

for (int col= 0; col < b[0].length; col++){

sum += b[row][col];

} // end of second loop

y[row]=sum;

}// end of first loop

// called method

selectionSort(y);

//for loop to print the employees with their hours

for(int i=0 ; i< y.length;i++){

System.out.println(" The employee " + i +" "+ "has "+ " " + y+" "+" hours");

}//End of for loop

}//End of main method

// sort method

public static void selectionSort(int [] list) {

//creat for loop to read index of array

for (int i = list.length - 1; i >= 1; i--) {

// Find the maximum in the list[0..i]

int currentMax = list[0];

int currentMaxIndex = 0;

//Creat for loop to sort the array

for (int j = 1; j <= i; j++) {

if (currentMax < list[j]) {

currentMax = list[j];

currentMaxIndex = j;

}//End of if condition

}//End of for loop

// Swap list with list[currentMaxIndex] if necessary;

if (currentMaxIndex != i) {

list[currentMaxIndex] = list;

list = currentMax;

}//End of if condition

}//End outer loop

}//End of method

}//End of class
#6

أنا عملت المحاوله واتمنى الحين تساعدني ..

#7
نيو هنا كتب:

أنا عملت المحاوله واتمنى الحين تساعدني ..

السلام عليكم

لاحظ ان السوال يطلب اسماء الموظفين و ساعات عمالهم بترتيب متناقص و ليس متزايد

محاولتك جيدا جدا و كانتا قريبا من الحل

لقد اضفت بعض التعديلات الخفيفة على البرنامج

هذا الصنف Worker

public class Worker {

 private String name;
 private int total_hours;

 //constructor
 public Worker(String nom,int heur){
 	this.name=nom;
 	this.total_hours=heur;
 }


 //seters and getters

	public String getName() {
    	return name;
	}

	public int getTotal_hours() {
    	return total_hours;
	}

	public void setName(String name) {
    	this.name = name;
	}

	public void setTotal_hours(int total_hours) {
    	this.total_hours = total_hours;
	}

}

و هذا الصنف الرائيسي

public class TwoD_Array { 

	/**
 	* @param args the command line arguments
 	*/



	public static void main(String[] args) {
 	int[ ][ ]b={{2,4,3,4,5,8,8},

{7,3,4,3,3,4,4},

{3,3,4,3,3,2,2},{9,3,4,7,3,4,1},

{3,5,4,3,6,3,8},{3,4,4,6,3,4,4,},

{3,7,4,8,3,8,4},{6,3,5,9,2,7,9}};

 	Worker []y=new Worker[8];


for (int row = 0; row <b.length; row++){

int sum = 0;

for (int col= 0; col < b[0].length; col++){

sum += b[row][col];

} 

y[row]=new Worker("Employee"+row,sum);


 }


selectionSort(y);

for(int i=y.length-1 ; i>=0 ;i--){

System.out.println(" The " + y.getName()+" "+ "has "+ " " + y.getTotal_hours()+" "+" hours");




	}
	}




public static void selectionSort(Worker [] list) {

//creat for loop to read index of array

for (int i = list.length - 1; i >= 1; i--) {

// Find the maximum in the list[0..i]

Worker currentMax = list[0];

int currentMaxIndex = 0;

//Creat for loop to sort the array

for (int j = 1; j <= i; j++) {

if (currentMax.getTotal_hours() < list[j].getTotal_hours()) {

currentMax = list[j];

currentMaxIndex = j;

}//End of if condition

}//End of for loop

// Swap list with list[currentMaxIndex] if necessary;

if (currentMaxIndex != i) {

list[currentMaxIndex] = list;

list = currentMax;

}//End of if condition

}//End outer loop

}//End of method

}//End of class

تم تعديل هذه المشاركة بواسطة sahraoui17 في 28 ديسمبر 2011 في 09:39

#8

بارك الله فيك أخي

#9

السلام عليكم ورحمة الله وبركاته

لقد حاولت حل البرنامج باسلوب مختلف حيث اننى مبتدئ فى الجافا

ولا اعلم الكثير فاعذرونى على حلى المبدئى

package main;
public class Main {
    public static void main(String[] args) {
 int a[][]={{2,4,3,4,5,8,8,0},{7,3,4,3,3,4,4,0},
            {3,3,4,3,3,2,2,0},{9,3,4,7,3,4,1,0},
            {3,5,4,3,6,3,8,0},{3,4,4,6,3,4,4,0},
            {3,7,4,8,3,8,4,0},{6,3,5,9,2,7,9,0}};
 int b[]={0,0,0,0,0,0,0,0};
 int c[]={0,0,0,0,0,0,0,0};
 int x,y,row,col,j,k,re;
 row=a[0].length;
 col=a.length;
 System.out.println("Employee No              Total Hours          C\n"); 
 //this part to calculate the sum on the last column 
  for(x=0;x<row;x++){
     for(y=0;y<col-1;y++){         
         a[x][col-1]+=a[x][y];
         b[x]=a[x][col-1];                                              
             }     
         }
  //this part to sort the elements 
  for (j=0;j<row;j++){
      for(k=j;k<row;k++){
          if(b[j]<b[k]){
              re=b[j];
              b[j]=b[k];
              b[k]=re;                             
          }
//this part to store the rank of every element          
          int m,n;
          for (m=0;m<row;m++){
              for(n=0;n<row;n++){
                  if(b[m]==a[n][col-1]){
                     if(m!=n){
                         c[m]=n;
                     }

                  }
              }
          }         
      }
//this part to print the elements before and after sort acorrding to thier
// sumation and thier rank also

      System.out.println("Employee  "+c[j]+ "     has      " +b[j]+ "    hours");
  }
         }


 }

وهذه هى النتائج

run:
Employee No              Total Hours          C

Employee  7     has      41    hours
Employee  6     has      37    hours
Employee  0     has      34    hours
Employee  4     has      32    hours
Employee  3     has      31    hours
Employee  1     has      28    hours
Employee  5     has      28    hours
Employee  2     has      20    hours
BUILD SUCCESSFUL (total time: 0 seconds)

تم تعديل هذه المشاركة بواسطة fmgret12 في 1 يناير 2012 في 00:03

1
#10
fmgret12 كتب:

السلام عليكم ورحمة الله وبركاته

لقد حاولت حل البرنامج باسلوب مختلف حيث اننى مبتدئ فى الجافا

ولا اعلم الكثير فاعذرونى على حلى المبدئى

package main;
public class Main {
    public static void main(String[] args) {
 int a[][]={{2,4,3,4,5,8,8,0},{7,3,4,3,3,4,4,0},
            {3,3,4,3,3,2,2,0},{9,3,4,7,3,4,1,0},
            {3,5,4,3,6,3,8,0},{3,4,4,6,3,4,4,0},
            {3,7,4,8,3,8,4,0},{6,3,5,9,2,7,9,0}};
 int b[]={0,0,0,0,0,0,0,0};
 int c[]={0,0,0,0,0,0,0,0};
 int x,y,row,col,j,k,re;
 row=a[0].length;
 col=a.length;
 System.out.println("Employee No              Total Hours          C\n"); 
 //this part to calculate the sum on the last column 
  for(x=0;x<row;x++){
 	for(y=0;y<col-1;y++){     	
     	a[x][col-1]+=a[x][y];
     	b[x]=a[x][col-1];                                              
         	} 	
     	}
  //this part to sort the elements 
  for (j=0;j<row;j++){
      for(k=j;k<row;k++){
          if(b[j]<b[k]){
              re=b[j];
              b[j]=b[k];
              b[k]=re;                         	
          }
//this part to store the rank of every element          
          int m,n;
          for (m=0;m<row;m++){
              for(n=0;n<row;n++){
                  if(b[m]==a[n][col-1]){
                 	if(m!=n){
                     	c[m]=n;
                 	}

                  }
              }
          }     	
      }
//this part to print the elements before and after sort acorrding to thier
// sumation and thier rank also

      System.out.println("Employee  "+c[j]+ " 	has      " +b[j]+ "    hours");
  }
     	}


 }

وهذه هى النتائج

run:
Employee No              Total Hours          C

Employee  7 	has      41    hours
Employee  6 	has      37    hours
Employee  0 	has      34    hours
Employee  4 	has      32    hours
Employee  3 	has      31    hours
Employee  1 	has      28    hours
Employee  5 	has      28    hours
Employee  2 	has      20    hours
BUILD SUCCESSFUL (total time: 0 seconds)

جيد

المهم النتائج

هذا الموضوع مغلق.

مواضيع مشابهة