-
Notifications
You must be signed in to change notification settings - Fork 0
/
CODE
120 lines (101 loc) · 2.69 KB
/
CODE
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
use std::collections::HashMap;
#[derive(Debug)]
struct Citizen {
name: String,
id: String, // Planet Earth NFT Passport
}
impl Citizen {
fn new(name: &str, id: &str) -> Self {
Citizen {
name: name.to_string(),
id: id.to_string(),
}
}
}
#[derive(Debug)]
struct Nation {
name: String,
id: String, // Nation DAO ID
}
impl Nation {
fn new(name: &str, id: &str) -> Self {
Nation {
name: name.to_string(),
id: id.to_string(),
}
}
}
#[derive(Debug)]
struct Company {
name: String,
id: String, // Company DAO ID
}
impl Company {
fn new(name: &str, id: &str) -> Self {
Company {
name: name.to_string(),
id: id.to_string(),
}
}
}
#[derive(Debug)]
struct PlanetaryDAO {
citizens: HashMap<String, Citizen>,
nations: HashMap<String, Nation>,
companies: HashMap<String, Company>,
}
impl PlanetaryDAO {
fn new() -> Self {
PlanetaryDAO {
citizens: HashMap::new(),
nations: HashMap::new(),
companies: HashMap::new(),
}
}
fn add_citizen(&mut self, name: &str, id: &str) {
let citizen = Citizen::new(name, id);
self.citizens.insert(id.to_string(), citizen);
}
fn add_nation(&mut self, name: &str, id: &str) {
let nation = Nation::new(name, id);
self.nations.insert(id.to_string(), nation);
}
fn add_company(&mut self, name: &str, id: &str) {
let company = Company::new(name, id);
self.companies.insert(id.to_string(), company);
}
fn display_citizens(&self) {
println!("Citizens:");
for citizen in self.citizens.values() {
println!("{:?}", citizen);
}
}
fn display_nations(&self) {
println!("Nations:");
for nation in self.nations.values() {
println!("{:?}", nation);
}
}
fn display_companies(&self) {
println!("Companies:");
for company in self.companies.values() {
println!("{:?}", company);
}
}
}
fn main() {
let mut planetary_dao = PlanetaryDAO::new();
// Adding citizens
planetary_dao.add_citizen("Alice", "NFT12345");
planetary_dao.add_citizen("Bob", "NFT67890");
// Adding nations
planetary_dao.add_nation("United States", "NATION001");
planetary_dao.add_nation("Canada", "NATION002");
// Adding companies
planetary_dao.add_company("TechCorp", "COMPANY001");
planetary_dao.add_company("GreenEnergy", "COMPANY002");
// Displaying all entities
planetary_dao.display_citizens();
planetary_dao.display_nations();
planetary_dao.display_companies();
}