الله يخليكم ساعدوني ابا حل الاسايمنت هذا لاني حاولت بس م عرفت ف جيت عندكم عسب تساعدوني
In this assignment, you will develop the complete code for a Java program. The questions given below are based on the lecture notes, and are intended to familiarize you with the concepts of classes, objects and methods.
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 mge 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
واتمنى تساعدوني ولكم جزيل الشكر والعرفان
Assignment 1 (Java Classes)
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 mge 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
واتمنى تساعدوني ولكم جزيل الشكر والعرفان
تعليق