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

(بدون عنوان)

مغلق
بدأه ريما م في 1 مايو 2007 · 4 رد · 567 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

عندي برنامج جافا بس ماعرفت اكمله مطلوب التعديل عليه

جعل array of Employee class

المستخدمة، كمتغير خاص بالـ Company Class ونوع الوصول لها private.

كتابة

الـ code الخاص بالـ methods التالية:

searchByName() & add_Hours() which are related to the Company class.

إضافة

الـ methods التالية للـ Company class وإمكانية استدعاؤهما أثناء Run باختيارهما من Menu:

ü setCompanyInfo(): allows the user to enter the company’s info, e.g. name, owner & location.

ü displayCompanyInfo(): prints the company’s info: name, owner, location & number of entered employees info.

أستخدم برنامج جافا 5.5 بانتظاركم أحبتي , وربي مايضيع أجر اللي يساعد : )

HomeWork.rar

#2

ماشاء الله ، كود ممتاز ، استمري على هذا العطاء

اختي لو تكتبين السؤال كامل هنا ، عشان أتأكد بان الكود يلبي متطلبات الواجب أو نعدل عليه

#3

هو البرنامج أبغى اجري عليه تعديلات معينه

التعديلات التي اريد اجراءها موجود في المرفقات

ياليت تساعدني اخوي عيسى في تعديله

java_HW1.doc

#4

المعلومات غير واضحه ، اكتب ماتريدين هنا بدون attachement انسخي الكود ثم اضغطي على زر كود ، واكتبي السؤال ،

هكذا سنساعدك عندما نرى الكود والسؤال ،

#5
/*
	Student Name:
	Number	  :
	Purpose	 :An array of 'Employee' class. Prompet the user to enter a choice
				   from a MENU :

			1: Enter the employee(s) information
					2: Change the hours rate cost
				 	3: Search by the employee's name
				 	4: Search by the employee's ID
				 	5: Display employees information
				 	6: Add hours to a specific employee
				 	7: Exit
*/

package mycompany;

import java.util.Scanner;

public class Company
{ 
	   public static final int MAX_EMP_NUMBER= 15;

	   private String name; 
	   private String owner;
	   private String location;   
		private Employee e[];

	   public Company()
	   {	  
			  name="";
			  owner="";
			  location="";
			  e=null;
	   }  // Constructor

	   public Company(String name,String owner,String location)
	   { 
			  this.name=name;
			  this.owner=owner;
			  this.location=location;  
			  e = new Employee[MAX_EMP_NUMBER];
			  for (int i=0;i<e.length;i++)
				  e=new Employee();	  
	   }  // Constructor  

	   public int setEmpInfo()
	   {
			  Scanner read=new Scanner(System.in);
			  int count=0;
			  String answer;

			  System.out.println("\nThis company can have (" + MAX_EMP_NUMBER + ") employees at most..");

			  do
			  {
				  e[count].setInfo();
				  count++;
				  System.out.println("Do you want to continue (Yes/No)? ");
				  answer=read.next();
			  }
			  while ( ((answer.equalsIgnoreCase("yes"))||(answer.equalsIgnoreCase("y"))) &&
					  (count<MAX_EMP_NUMBER) );
			  read.nextLine(); //to get rid of rest of line
			  return count;
	   }// end of set

	   public void displayEmpInfo(int count)
	   {
			  Scanner read=new Scanner(System.in);
			  if (count!=0)
				  for (int j=0;j<count;j++)
					   e[j].showInfo();
			  else
				  System.out.println("There is no information for employees to display");

			  read.nextLine(); //wait
	   }// end of display

	   public void searchByName(int count)
	   {
		 Scanner read=new Scanner(System.in);
			  String name;
			  boolean found=false;

			  if (count!=0)
			  {
				  System.out.println("Enter the name of the employee to be searched: ");
				  name=read.nextLine();
				  read.nextLine(); //to get rid of rest of line 
				  for (int j=0;j<count;j++)
				  {
					   found=e[j].search_name(name);
					   if (found)
						   break;	 
				  }

				  if (!found)
					  System.out.println("The employee is not found");
			 }
			 else
				 System.out.println("There is no information to search for any employee");

			 read.nextLine(); //wait  

		}// end of searchByName

		public void searchByID(int count)
		{
			   Scanner read=new Scanner(System.in);
			   int id;
			   boolean found=false;

			   if (count!=0)
			   {
				   System.out.println("Enter the ID of the employee to be searched: ");
				   id=read.nextInt();
				   read.nextLine(); //to get rid of rest of line 
				   for (int j=0;j<count;j++)
				   {
						found=e[j].search_ID(id);
						if (found)
							break;	 
				   }

				   if (!found)
					   System.out.println("The employee is not found");
			  }
			  else
				  System.out.println("There is no information to search for any employee");

			  read.nextLine(); //wait  
		}// end of searchByID

		public void change_HourPrice()
		{
			   Scanner read=new Scanner(System.in);
			   int newPrice;
			   String answer;

			   System.out.println("Do you really want to change the hour fee (Yes/No)? "); //fee=pay
			   answer=read.nextLine();
			   if ((answer.equalsIgnoreCase("yes"))||(answer.equalsIgnoreCase("y")))
			   {
				   System.out.println("Enter the new hour fee: ");
				   newPrice=read.nextInt();
				   read.nextLine(); //to get rid of rest of line 
				   Employee.setHourPrice(newPrice); //call a static method
				   System.out.println("\n** the hour fee has been changed successfully **");
			   }

			   read.nextLine(); //wait				 
		}// end of change_HourPrice

		public void add_Hours(int count)
		{

		  Scanner read=new Scanner(System.in);
			   int h;


			   if (count!=0)
			   {
				   System.out.println("Enter the hours of the employee to be added: ");
				   h=read.nextInt();
				   read.nextLine(); //to get rid of rest of line 
				   for (int j=0;j<count;j++)
				   {
						found=e[j].addHours(h);

				   }


			  }
			  else
				  System.out.println("There is no employees to add hours to");

			  read.nextLine(); //wait  


		}// end of add_Hours

		public int menu()
		{
			  Scanner read=new Scanner(System.in); 
			  int choice;

			   System.out.println("******************************************************");
			   System.out.println("****				   MENU					   ****");
			   System.out.println("******************************************************");
			   System.out.println("****	 1: Enter the employee(s) information	 ****");
			   System.out.println("****	 2: Change the hours rate cost			****");
			   System.out.println("****	 3: Search by the employee's name		 ****");
			   System.out.println("****	 4: Search by the employee's ID		   ****");
			   System.out.println("****	 5: Display employees information		 ****");
			   System.out.println("****	 6: Add hours to a specific employee	  ****");
			   System.out.println("****	 7: Exit								  ****");
			   System.out.println("******************************************************\n");

			   System.out.println("Enter your choice: ");
			   choice=read.nextInt();
			   read.nextLine(); //to get rid of rest of line

			   return choice;
		} //end of menu

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

		public static void main(String[] args)
		{
			 //Scanner read=new Scanner(System.in);
			 //Company c=new Company();
			 Company c=new Company("Dreams CO. for Women Clothes","Angel A.T","K.S.A");			 
			 int number=0; // the number of input employees
			 int choice;



			 do
			 {
				choice=c.menu();

				switch (choice)
				{
					case 1:number=c.setEmpInfo();
						   break;

					case 2:c.change_HourPrice();
						   break;

					case 3:c.searchByName(number);
						   break;

					case 4:c.searchByID(number);
						   break;

					case 5:c.displayEmpInfo(number);
						   break;

					case 6:c.add_Hours(number);
						   break;
					}// end of switch

			  }while (choice!=7); // end of do_while

			 System.exit(0);   //read.nextLine(); 
		}// end of main
}//end of Company class




تم

لا بد من صنعاء وان طال السفر

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

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