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

مُسـاعَده فـِ الجَــافا ..

بدأه غــسق في 15 أبريل 2011 · 3 رد · 448 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السَّـلام عليكم ورحمـة الله ..

عندي أسـايمنت أصابني بـ الأرق .. فـ لـو مُمكن أحد يسـاعدني فيه ويصحح أخطـائي فـِ الحَـل مشكـوريين لأن عليه كثيـر درجـات وأحـاتيهن ..

السّـؤال الأوّل :

Creating a class

Create a class Employee with the following variables and methods:

Variables: name: Name of the employee (Type: String)

salary: The monthly paid salary (Type: double)

Constructor: Write a default constructor, also write a second constructor with two parameters (name and salary).

Methods: getName(): to return the name.

getSalary(): to return the salary.

raiseSalary(double byPercent): this method raises the employee’s salary by a certain percentage.

printInfo(): Prints name and salary.

Compile this program Note that this code is just a class definition, and is not a Java application, and hence is not runnable.

مُحاولتي فِي الحَــل :

public class Employee
{
public String name;
public double salary;
public Employee()
{
name="Shooq";
salary=0;
}
public Employee(String A,double B)
{
name=A;
salary=B;
}
public String getName()
{
return name;
}
public double getSalary()
{
return salary;
}
public void raiseSalary(double percent)
{
salary=salary+(salary / percent);
}
public void printLnfo()
{
System.out.println("Employee Name:"+name+",Salary:"+salary);
}
}

السـؤال الثَّاني :

Creating an application and a set of objects

Write a Java application (driver class) MyProg” to create a set of objects emp1, emp2, emp3 of the class Employee. For each object, define initial values for name, and salary through the class constructor. Call the various methods of class Employee on these objects of the class. Compile and run the program to verify the output.

مُحاولتي فِي الحَــل :

public class MyProg
{
 public static void main(String[]args)
 {
 Employee emp1=new Employee("Shooq Ahmad",1000);
 Employee emp2=new Employee("Amal Said",500);
 Employee emp3=new Employee("noor Ali",600.5);
 System.out.print(emp1.getName());
 System.out.print("'s salary is:OR");
 System.out.println(emp1.getSalary());
 emp1.raiseSalary(10);
 System.out.print("After the raise,");
 System.out.print(emp1.getName());
 System.out.print("'s salary is:OR");
 System.out.println(emp1.getSalary());
 }
}

Output:
Shooq Ahmad's salary is:OR1000.0
After the raise,Shooq Ahmad's salary is:OR1100.0
Finished executing

السّؤال الثالث :

Need for Restricted Access to Variables

Now, add the following lines to MyProg” (inside main”):

emp3 = emp1;

emp3.salary=1000; //***

emp1.printInfo(); //print information of employee 1

Even though the above code has apparently changed the salary of ‘emp3’, you will notice that the salary of ‘emp1’ is changed also to 1000. Explain why.

How will you disallow direct modification of the salary such as that given in line *** above?

مافهمتش حَاجه :sad: .. !

السّـؤال الـرابـع :

Set the access to the constructor of Employee to ‘private’. Compile Employee.java and MyProg.java. Run MyProg. Explain what's happening.

وأيضا ً مفهمتش حَاجه :sad: .. !!

السـؤال الخَامِس :

Implementing a student class

Design a class to manage student results in a subject. A unique student number identifies each student. During the course of the subject, each student completes three assignments (representing 40% of the final mark but each scored out of 100) and an examination (also scored out of 100). The final mark is calculated by multiplying the sum of the assignments by 0.133 and the examination by 0.6 and adding the two products together. The class will allow a user to update an assignment mark or an examination mark, and print the final mark along with the student number for each student.

You must do the following:

Identify the class attributes and methods, draw the UML class diagram.

Write the java code for the class

مُحاولتي فِي الحَــل :

public class Student
 {
    int id;
    double ass1, ass2, ass3, exam, finalMark;
    public Student(int id, double ass1, double ass2, double ass3, double exam)
 {
        this.ass1 = ass1;
        this.ass2 = ass2;
        this.ass3 = ass3;
        this.exam = exam;
        this.id = id;

    }
    void finalResult(Student s) {
        s.finalMark = 0.4 / 3 * (ass1 + ass2 + ass3) + 0.6 * exam;
        System.out.println(s.finalMark);
    }
    public static void main(String[] args) {
        Student s1 = new Student(0, 55, 66, 77, 90);
        s1.finalResult(s1);
    }
}

*

طَبعا ً مُش مقتنعه فـ حلـولي علشـان كـذا جيت أسـأل أهـل الخــبـرة :unsure: ..

طبيعة دكـاتـرتي فـالجَامعة يعطونـا الأســايمنت فـوق قُدراتنا وبعيد كُل البُعد عن اللي نـدرسـه .. واختبـاراتهُم أسهـل عن الأسايمنت :mellow: ..

ياليت اللي عنده خلفيـه عن الجـافا يســاعدني مشكـورا ً ..
#2
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author oracle_java
 */
public class Employee {

	private String name;
	private double salary;

	public Employee() {
	}

	public Employee(String name, double salary) {
    	this.name = name;
    	this.salary = salary;
	}

	public String getName() {
    	return name;
	}

	public double getSalary() {
    	return salary;
	}

	public void raiseSalary(double percent) {
    	salary = salary + (salary * percent);
	}

	public void printLnfo() {
    	System.out.println("Employee Name: " + name + ",Salary: " + salary);
	}
}

بالتوفيق


﴿وَمَا كَانَ اللَّهُ لِيُعَذِّبَهُمْ وَأَنْتَ فِيهِمْ ۚ وَمَا كَانَ اللَّهُ مُعَذِّبَهُمْ وَهُمْ يَسْتَغْفِرُونَ﴾

الأنفال ۳۳                                  
 

#3

مشكـور كثير كثير أخي MOHAMED FATHEI على مُساعدتك فالسؤال الأول .. الله يوفقك ويرزقك كل اللي تتمناه يااا رب ..

ياليت حد يساعدني في باقي الأسئلة .. وممنونه ليكم .. بارك الله فيكم ..

#4

سؤالك مخالف .. لكن سأضع لك الترجمة .. :blush:

اقتباس

السـؤال الثَّاني :

Creating an application and a set of objects

Write a Java application (driver class) MyProg” to create a set of objects emp1, emp2, emp3 of the class Employee. For each object, define initial values for name, and salary through the class constructor. Call the various methods of class Employee on these objects of the class. Compile and run the program to verify the output.

يقولك انشئ عدة كائنات من الفئة employee مع مدخلات مختلفة وتحقق من النتائج.. أظن سهله :)

اقتباس

السّؤال الثالث :

Need for Restricted Access to Variables

Now, add the following lines to MyProg” (inside main”):

emp3 = emp1;

emp3.salary=1000; //***

emp1.printInfo(); //print information of employee 1

Even though the above code has apparently changed the salary of ‘emp3’, you will notice that the salary of ‘emp1’ is changed also to 1000. Explain why.

How will you disallow direct modification of the salary such as that given in line *** above?

نحتاج نضيف بعض القيود على المتغيرات ، الآن أضف الأسطر التالية :

emp3 = emp1;
emp3.salary=1000; //***
emp1.printInfo(); //print information of employee 1

ليش تغيرت قيم الكائن emp1 وضح لماذا؟ :)

لو طبعت الآن قيم الكائنين ستكون بنفس القيمة..

كيف نجعل الوصول إلى التعديل على المرتب مقيد ؟ :)

اقتباس

Set the access to the constructor of Employee to ‘private’. Compile Employee.java and MyProg.java. Run MyProg. Explain what's happening.

غير نوع دالة البناء في الفئة Employee من public إلى private ثم أعد تشغيل التطبيق ، وضح ماذا يحدث؟ :)

..

الخامس أعتقد واضح

تحياتي

تم تعديل هذه المشاركة بواسطة JavaPorgrammer في 16 أبريل 2011 في 00:57

1

عفواً أحبتي انقطاعي بسبب الدراسة دعواتكم بالتوفيق..

{ لا ينال العلم مستحٍ ولا مستكبر }

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