forked from flxcp/iitm.bs
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGA.Week.08.2.java
More file actions
75 lines (61 loc) · 1.73 KB
/
GA.Week.08.2.java
File metadata and controls
75 lines (61 loc) · 1.73 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
import java.util.*;
class Items implements Cloneable {
public String[] item;
public Items(String[] itemName) {
this.item = itemName;
}
@Override
public String toString() {
String output = "";
for (String it : item) {
output += it + " ";
}
return output;
}
@Override
protected Object clone() throws CloneNotSupportedException {
String[] cloneItemsList = Arrays.copyOf(item, item.length);
Items cloneItems = new Items(cloneItemsList);
return cloneItems;
}
}
class Customer implements Cloneable {
String name;
Items items;
Customer(String name, Items items) {
this.name = name;
this.items = items;
}
public void setName(String s) {
this.name = s;
}
@Override
public String toString() {
return name + " " + items;
}
public Items getItems() {
return items;
}
@Override
protected Customer clone() throws CloneNotSupportedException {
Customer cs = (Customer) super.clone();
cs.items = (Items) items.clone();
return cs;
}
}
public class Order {
public static void main(String[] args) throws CloneNotSupportedException {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(); // number of items
String[] itm = new String[n];
for (int i = 0; i < n; i++) {
itm[i] = sc.next(); // list of items
}
var c1 = new Customer("naresh", new Items(itm));
Customer c2 = c1.clone();
c2.getItems().item[0] = sc.next(); // Update first item of c2
c2.setName("suresh"); // Update name of c2
System.out.println(c1);
System.out.println(c2);
}
}