forked from flxcp/iitm.bs
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGA.Week.02.3.java
More file actions
65 lines (53 loc) · 1.55 KB
/
GA.Week.02.3.java
File metadata and controls
65 lines (53 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.util.*;
class Employee
{
String eid;
String ename;
String eprojects[];
//Define all the required methods here
Employee(String id, String name, String[] project){
ename = name;
eid = id;
eprojects = project;
}
Employee(Employee obj) {
eid = obj.eid;
ename = obj.ename;
eprojects = obj.eprojects.clone();
}
public String pArray(String[] array){
String rStr = "";
for (String val : array) {
rStr += val+":";
}
return rStr;
}
public void display() {
System.out.println("id:"+eid);
System.out.println("name:"+ename);
System.out.println("projects:");
System.out.println(pArray(eprojects));
}
public void mutator()
{
this.ename = "Mr "+ this.ename;
this.eprojects[0] = null;
}
}
public class FClass
{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
String project[] = {"P001","P002","P003"};
//Enter the id of employee
String id = s.nextLine();
//Enter the name of employee
String name = s.nextLine();
Employee e1 = new Employee(id,name,project);
Employee e2 = new Employee(e1);
//The copy constructor must copy all the data members.
e1.mutator();
e2.display();
}
}