-
Notifications
You must be signed in to change notification settings - Fork 0
/
Relationship-in-java-References
99 lines (86 loc) · 3.21 KB
/
Relationship-in-java-References
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package test;
public class Address {
public long hNo;
public String sName;
public String city;
public int pinCode;
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
package test;
public class Contact {
public String mailId;
public long phNo;
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
package test;
public class DisplayDetails {
public void dis(Employee e) {
System.out.println(e.toString());
}
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
package test;
public class Salary {
public long bSal;
public long totSal;
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
package test;
public class Employee {
public long eId;
public String eName;
public String Desc;
public Address ad;// creating reference variable
public Contact co;// creating reference variable
public Salary sal;// creating reference variable
public Employee(Address ob1, Contact ob2, Salary ob3)
{
ad = ob1;
co = ob2;
sal = ob3;
}
public String toString() {
return eId+"\n"+eName+"\n"+Desc+"\n"+ad.sName+"\n"+ad.city+"\n"+ad.hNo+"\n"+ad.pinCode+"\n"+co.mailId+"\n"+co.phNo+"\n"+sal.bSal+"\n"+sal.totSal;
}
}
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
package test;
public class EmpRegistration {
public void registration(java.util.Scanner s, Employee e) {
System.out.println("Give your details for registration");
System.out.println("Enter the house number");
e.ad.hNo = Long.parseLong(s.nextLine());
System.out.println("Enter the street name");
e.ad.sName = s.nextLine();
System.out.println("Enter the city name");
e.ad.city = s.nextLine();
System.out.println("Enter your mailid");
e.co.mailId=s.nextLine();
System.out.println("Enter your register phone number");
e.co.phNo = Long.parseLong(s.nextLine());
System.out.println("Enter your basic salary");
e.sal.bSal=Long.parseLong(s.nextLine());
System.out.println("Enter your total salary");
e.sal.totSal=Long.parseLong(s.nextLine());
System.out.println("Enter the pincode number of your area");
e.ad.pinCode = s.nextInt();
}
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
package maccess;
import test.*;
import java.util.*;
public class DemoReference {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
Address ad = new Address();
Contact co = new Contact();
Salary sal = new Salary();
Employee em = new Employee(ad, co, sal);
EmpRegistration reg= new EmpRegistration();
reg.registration(s,em);
DisplayDetails dis = new DisplayDetails();
dis.dis(em);
s.close();
}
}