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

مساعدة في حل سؤال بلغة الجافا

بدأه هوتميلكوم في 2 نوفمبر 2010 · 10 رد · 1,210 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

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

أتمنى منكم اخوتي مساعدتي لحل هذا السؤال بلغة الجافا الليلة فأنا مبتدئة

وعندي غداً امتحان في هذه المادة ولم أستطع حل هذا السؤال

حاولت عدة مرات لكن لم يعمل البرنامج معي,,

السؤال هو:

Problem Specification

Suppose that you were asked to write a program that can process employees records (سجلات) located in an input file named employees.data and write the new data to another file named new_employees.data. Note that every record is represented in one line.

The input file is textual, and contains the data as follows:

employees.data

ACT1032 Wael,Naser Ramallah-1230 650

ACT230 Maram,Ali Nablus-234 860

MGT1441 Salem,Rami Ramallah-2355 670

HRM2331 Ahmad,Salah Jerico-343 1200

………….

………

…..

As you can see from above, the file contains unknown number of records and every line (record) has exactly the same format, which consists (كل سطر يتكون من 4 اقسام) of 4 parts:

• First part represents the department and employee number,

example: ACT1032 : Accounting department, and employee number = 1032. Note also that departments are always represented in three characters upper case, according to the following department key table:

ACT Accounting

MGT Management

HRM Human Resources

• Second part represents: first name,second name

example: Wael,Naer : first name = Wael and last name = Naser

• Third part represents city name-B.O. Box number

example Ramallah-1230 : city = Ramallah and B.O.Box = 1230

• And last part is the salary in US Dollars

So what your program should do?

• You need to create a class the represents an employee, having these fields: number, first name, second name, city, bo box and salary. You should decide the appropriate data type for each field, and decide on appropriate constructors.

• All above fields should be private, and provide getters and setters

• Your main class should call a method fillData() that will:

o Open file employees.data

o Read data line-by-line, and process each line by extracting data and storing it in employee object.

o You should use the departments key table above to discover full department name and store it in the object. And also all other data: number, first name, last name, …etc

o The method at the end will return an array of all employees

• Then call another method and pass it the array and will write the following information on file new_employees.data respectively (بالترتيب)

o How many employee in every department

o How many employees live in Nablus

o The average of salaries of all employees.

o You can have as many methods as you think appropriate

وجزاكم الله خيراً

alwehda92 متواجد حالياً أضافة تقييم إلى alwehda92 تقرير بمشاركة سيئة تعديل / حذف المشاركة

#2

اخى الكريم

يجب وضع محاولاتك كى لا يتم اغلاق المووضوع

فقره حل الواجبات

Software Developer
Mahmoudkelany.com


 

#3

يمنع وضع اي اجابة لحين طرح محاولات السائل

اي رد قبل المحاولات سيتم حذفه و شكرا

#4

ما هو محدش حط اهووو

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

Software Developer
Mahmoudkelany.com


 

#5

السلام علكم

حاولت حل السؤال بما لدي من معلومات عن هذا الموضوع

أتمنى ان تساعدوني بالحل الصحيح لأن امتحاني غداً بإذن الله..

import java.util.Scanner;

public class Employee{

public static void main(String[]args){

java.io.File file=new java.io.File("employee.data");

if(file.exists()){

system.out.println("File already exists");

system.exit(0);

}

java.io.PrintWriter output = new java.io.PrintWriter(file);


Scanner input = new Scanner(new File(file));

while(input.hasNext()){

int depnum=input.nextInt();

int empnum=input.nextInt();

double salary=input.nextDouble();

String fistName=input.next();

String lastName = input.next();

string line=input.nextLine();


output.close();
}

تم تعديل هذه المشاركة بواسطة .S.T.A.L.K.E.R في 3 نوفمبر 2010 في 01:32 — السبب: add code tag

#6

رجاءً حد يساعدني

#7

مممكن حضرتك تعرضى السوال باللغه العربيه

لان السوال طويل جدا

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

Software Developer
Mahmoudkelany.com


 

#8

السلام عليكم

السؤال يطلب كتابة برنامج لمعالجة سجلات موظفين عن طريق ملف ادخال اسمه employee.data وكتابة البيانات على ملف جديد اسمه new_employees.data بحيث يتم تمثيل كل سجل في سطر واحد,,

ملف الادخال يجب ان يكون بصيغة txt وتمثيل البيانات يكون على النحو التالي

employees.data

ACT1032 وائل ، رام الله ، ناصر 1230 650

ACT230 مرام ونابلس علي 234 860

MGT1441 سالم ، رامي رام الله ، 2355 670

HRM2331 أحمد صلاح اريحا 343 1200

.............

.........

...

لملف يحتوي على عدد غير معروف من السجلات وكل سطر (سجل)يكون نفس الشكل ، وكل سطر يتكون من 4 اقسام) من 4 أجزاء :

• الجزء الأول يمثل عدد الإدارة والموظفين ،

على سبيل المثال : ACT1032 : قسم المحاسبة ، والموظف عدد = 1032.

دائماً يجب أن تكون أول ثلاث حروف بالupper case

كما في المثال التالي

ACT Accounting

MGT Management

HRM Human Resources

• يمثل الجزء الثاني : الاسم الأول ، الاسم الثاني

example: Wael,Naer : first name = Wael and last name = Naser

الجزء الثالث يمثل اسم المدينة و-B.O. Box number

example Ramallah-1230 : city = Ramallah and B.O.Box = 1230

الجزء الاخير هو عبارة عن الراتب بالدولا ر الامريكي

المهام التي يجب ان يقوم بها لبرنامج:

نشاء كلاس اسمه employee يحتوي على ثلاثة حقول

number, first name, second name, city, bo box and salary

يجب ان تقرر ما هو نوع البيانات المناسب لكل حقل والconsturctor المناسب لذلك

جميع الحقول يجب ان تكون private

وتستخدم getters and setters

الmain class يجب ان يستدعيmethod fillData()

employees.data والتي تعمل على فتح ملف

قراءة كل سطر على حدة ومعالجة كل سطر عن طريق استخراج البيانات وتخزينهاا في employee object.

يجب استخدام ال الdepartments key table

في الاعلى لاكتشاف الاسم الكامل وتخزينه في object

وكل البيانات الاخرى number, first name, last name, …etc

من ثم استدعاء مثود اخرى وتمرير array

لها وكتابة المعلومات التالية على ملفnew_employees.data

بالترتيبo How many employee in every department

o How many employees live in Nablus

o The average of salaries of all employees.

o You can have as many methods as you think appropriate

بالاضافة الى ذلك يطلب البرنامج استخدام stringbuffer

لمعالجة النص

شكراً لكل من مر هنا..:)

#9

لقد وضعت ترجمة السؤاال الى اللغة العربية

رجاءً من يستطيع حل السؤال بالطريقة الصحيحة ان يضعه لي في هذا الموضوع الليلة أو غداً صباحاً

وشكرا لكم

#10

رلرفع الموضوع

\\اتمنى ان يستطيع احد االاخوة مساعدتي لأني لم تنجح المحاولة معي

#11

هذه محاولة اخرى لكتابة الكلاس

لم اعرف كيف أكمل كتابة بقية الحل

public class Employee{
private int number;
private int depnum;
private string firstname;
private string secondname;
private string city;
private int box;
private double salary;

public Employee(){

}
public Employee (int number,string firstname,string secondname,string city,int box,double salary){
}
setNumber(number);
setFirstname(firstname);
setSecondname(secondname);
setCity(city);
setSalary(salary);
}
public int getnumber(){
return number;
}
public void setNumber(int number){
this.number=number;
}
public string getName(){
return name;
}
public void setFirstname(string firstname){
this.firstname=firstname;
}
public void setSecondname(string secondname){
this.secondname=name;
}
public string getSecondname(){
return secondname;
}
public string getCity(){
return string city;
}
public void setCity(string city){
this.city=city;
}
public int getPox(){
return pox;
}
public void setBox(int box){
this.box=box;
}
public double getSalary(){
return salary;
}
public void setSalary(double salary){
this.salary=salary;
}

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