-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
129 lines (106 loc) · 3.44 KB
/
Program.cs
File metadata and controls
129 lines (106 loc) · 3.44 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
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
public class JobApplication
{
public string? CompanyName { get; set; }
public string? RoleType { get; set; }
public string? SalaryRange { get; set; }
public string? BusinessType { get; set; }
public bool Rejected { get; set; }
public string? RejectionStage { get; set; }
public DateTime ApplicationDate { get; set; }
public virtual void DisplayInfo()
{
Console.WriteLine($"Company: {CompanyName}");
Console.WriteLine($"Role Type: {RoleType}");
Console.WriteLine($"Salary Range: {SalaryRange}");
Console.WriteLine($"Business Type: {BusinessType}");
Console.WriteLine($"Application Date: {ApplicationDate:yyyy-MM-dd}");
Console.WriteLine($"Rejected: {(Rejected ? "Yes" : "No")}");
if (Rejected)
Console.WriteLine($"Rejection Stage: {RejectionStage}");
}
}
public class RemoteJobApplication : JobApplication
{
public string? WorkTimeZone { get; set; }
public override void DisplayInfo()
{
base.DisplayInfo();
Console.WriteLine($"Work Time Zone: {WorkTimeZone}\n");
}
}
public class HybridJobApplication : JobApplication
{
public int RemoteDays { get; set; }
public int OnsiteDays { get; set; }
public string? OfficeCity { get; set; }
public override void DisplayInfo()
{
base.DisplayInfo();
Console.WriteLine($"Remote Days: {RemoteDays}");
Console.WriteLine($"Onsite Days: {OnsiteDays}");
Console.WriteLine($"Office City: {OfficeCity}\n");
}
}
public class OnsiteJobApplication : JobApplication
{
public string? OfficeCity { get; set; }
public override void DisplayInfo()
{
base.DisplayInfo();
Console.WriteLine($"Office City: {OfficeCity}\n");
}
}
public class ApplicationData
{
public List<JsonElement> Applications { get; set; } = new();
}
class Program
{
static void Main(string[] args)
{
string jsonPath = "applications.json";
if (!File.Exists(jsonPath))
{
Console.WriteLine("JSON file not found.");
return;
}
string json = File.ReadAllText(jsonPath);
var options = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
};
ApplicationData? data =
JsonSerializer.Deserialize<ApplicationData>(json, options);
if (data == null)
{
Console.WriteLine("Failed to deserialize JSON.");
return;
}
Console.WriteLine("Job Applications:\n");
foreach (var element in data.Applications)
{
string? roleValue = element.GetProperty("RoleType").GetString();
string role = (roleValue ?? "onsite").ToLower();
JobApplication? job;
switch (role)
{
case "remote":
job = JsonSerializer.Deserialize<RemoteJobApplication>(element, options);
break;
case "hybrid":
job = JsonSerializer.Deserialize<HybridJobApplication>(element, options);
break;
default:
job = JsonSerializer.Deserialize<OnsiteJobApplication>(element, options);
break;
}
if (job != null)
job.DisplayInfo();
}
}
}