-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathQuestion.java
More file actions
137 lines (129 loc) · 3.23 KB
/
Question.java
File metadata and controls
137 lines (129 loc) · 3.23 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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import java.util.HashMap;
import java.util.HashSet;
class Address
{
private String state;
private String city;
private String pinCode;
private String steetAddress;
@Override
public int hashCode(){
return Integer.parseInt(pinCode);
// if(city.equalsIgnoreCase("delhi")){
// return 10;
// }
// else
// {
// return 20;
// }
}
@Override
public boolean equals(Object o){
boolean isFound = false;
if(o instanceof Address){
Address address = (Address)o; // Downcasting
if(this.city.equals(address.city)
&& this.state.equals(address.state)
&& this.pinCode.equals(address.pinCode)
&& this.steetAddress.equals(address.steetAddress)){
isFound = true;
}
}
return isFound;
}
Address(String state, String city, String pinCode, String streetAddress){
this.state = state;
this.city = city;
this.pinCode = pinCode;
this.steetAddress = streetAddress;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getPinCode() {
return pinCode;
}
public void setPinCode(String pinCode) {
this.pinCode = pinCode;
}
public String getSteetAddress() {
return steetAddress;
}
public void setSteetAddress(String steetAddress) {
this.steetAddress = steetAddress;
}
@Override
public String toString() {
return "Address [state=" + state + ", city=" + city + ", pinCode=" + pinCode + ", steetAddress=" + steetAddress
+ "]";
}
}
class CashCustomer
{
private int id;
private String name;
private double balance;
private HashMap<String,HashSet<Address>> addressMap= new HashMap<>();
CashCustomer(int id , String name, double balance){
this.id = id;
this.name =name;
this.balance = balance;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public HashMap<String, HashSet<Address>> getAddressMap() {
return addressMap;
}
public void setAddressMap(HashMap<String, HashSet<Address>> addressMap) {
this.addressMap = addressMap;
}
@Override
public String toString() {
return "CashCustomer [id=" + id + ", name=" + name + ", balance=" + balance + ", addressMap=" + addressMap
+ "]";
}
}
public class Question {
public static void main(String[] args) {
// TODO Auto-generated method stub
HashMap<String,CashCustomer> customerMap = new HashMap<>();
HashSet<Address> officeSet = new HashSet<>();
Address delhiOffice = new Address("Delhi","Delhi","11007","Delhi-7");
officeSet.add(delhiOffice);
Address delhiOffice2 = new Address("Delhi","Delhi","11007","Delhi-7");
officeSet.add(delhiOffice2);
HashMap<String,HashSet<Address>> addressMap = new HashMap<>();
addressMap.put("office", officeSet);
CashCustomer amit = new CashCustomer(1001,"amit",9999);
amit.setAddressMap(addressMap);
customerMap.put(amit.getName(),amit);
CashCustomer ram = new CashCustomer(1002,"ram",2222);
customerMap.put(ram.getName(),ram);
System.out.println(customerMap);
}
}