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

[مخالف - طلب حل : ]سؤال في الجافا

مغلق
بدأه Alamrani في 10 أبريل 2011 · 1 رد · 642 مشاهدة · في قسم البرمجة بــ Javascript
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

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.

2. 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.

3. 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?

4. Access Modifier (visibility) for Constructor

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

5. 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

#2

الأخ الكريم/الأخت الكريمة

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

مرحباً بكم في منتدى الفريق العربي للبرمجة

تأسف إدارة المنتدى لغلق الموضوع وذلك لمخالفته قوانين المشاركات، فقرة طلب حل الواجبات والتمارين.

قواعد طرح المشاركات

/index.php?showtopic=29343

شاكرين لكم حُسن تعاونكم

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

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