Question: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Text.Json; using System.IO; namespace AtomApp { class Program { //add the following statement in

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Text.Json; using System.IO;

namespace AtomApp { class Program { //add the following statement in global scope //To create a collection to work with static List elements = new List();

const string FIRST_FILE = "first-atom.json"; const string ALL_FILE = "all-atoms.json";

//test harness static void AddAtoms() { //add the following statement to a class method elements.Add(Atom.Parse("Hydrogen 1 0 1.0079 H")); elements.Add(Atom.Parse("Helium 2 2 4.0026 He")); ; elements.Add(Atom.Parse("Lithium 3 4 6.941 Li")); ; elements.Add(Atom.Parse("Beryllium 4 5 9.0122 Be")); elements.Add(Atom.Parse("Boron 5 6 10.811 B")); elements.Add(Atom.Parse("Carbon 6 6 12.0107 C")); elements.Add(Atom.Parse("Holmium 67 98 164.9303 Ho")); elements.Add(Atom.Parse("Erbium 68 99 167.259 Er")); elements.Add(Atom.Parse("Thulium 69 100 168.9342 Tm")); elements.Add(Atom.Parse("Ytterbium 70 103 173.04 Yb")); elements.Add(Atom.Parse("Lutetium 71 104 174.967 Lu")); elements.Add(Atom.Parse("Hafnium 72 106 178.49 Hf")); elements.Add(Atom.Parse("Tantalum 73 108 180.9479 Ta")); elements.Add(Atom.Parse("Tungsten 74 110 183.84 W")); elements.Add(Atom.Parse("Rhenium 75 111 186.207 Re")); elements.Add(Atom.Parse("Osmium 76 114 190.23 Os")); elements.Add(Atom.Parse("Iridium 77 115 192.217 Ir")); elements.Add(Atom.Parse("Platinum 78 117 195.078 Pt")); elements.Add(Atom.Parse("Gold 79 118 196.9665 Au")); elements.Add(Atom.Parse("Mercury 80 121 200.59 Hg")); elements.Add(Atom.Parse("Thallium 81 123 204.3833 Tl")); elements.Add(Atom.Parse("Lead 82 125 207.2 Pb")); elements.Add(Atom.Parse("Bismuth 83 126 208.9804 Bi")); elements.Add(Atom.Parse("Polonium 84 125 209 Po")); elements.Add(Atom.Parse("Astatine 85 125 210 At")); elements.Add(Atom.Parse("Radon 86 136 222 Rn")); elements.Add(Atom.Parse("Francium 87 136 223 Fr")); elements.Add(Atom.Parse("Radium 88 138 226 Ra")); elements.Add(Atom.Parse("Actinium 89 138 227 Ac")); elements.Add(Atom.Parse("Protactinium 91 140 231.0359 Pa")); elements.Add(Atom.Parse("Thorium 90 142 232.0381 Th")); elements.Add(Atom.Parse("Neptunium 93 144 237 Np")); elements.Add(Atom.Parse("Uranium 92 146 238.0289 U")); elements.Add(Atom.Parse("Americium 95 148 243 Am")); elements.Add(Atom.Parse("Plutonium 94 150 244 Pu")); elements.Add(Atom.Parse("Curium 96 151 247 Cm")); elements.Add(Atom.Parse("Berkelium 97 150 247 Bk")); elements.Add(Atom.Parse("Californium 98 153 251 Cf")); elements.Add(Atom.Parse("Einsteinium 99 153 252 Es")); elements.Add(Atom.Parse("Fermium 100 157 257 Fm")); elements.Add(Atom.Parse("Mendelevium 101 157 258 Md")); elements.Add(Atom.Parse("Nobelium 102 157 259 No")); elements.Add(Atom.Parse("Rutherfordium 104 157 261 Rf")); elements.Add(Atom.Parse("Lawrencium 103 159 262 Lr")); elements.Add(Atom.Parse("Dubnium 105 157 262 Db")); elements.Add(Atom.Parse("Bohrium 107 157 264 Bh")); elements.Add(Atom.Parse("Seaborgium 106 160 266 Sg")); elements.Add(Atom.Parse("Meitnerium 109 159 268 Mt")); elements.Add(Atom.Parse("Roentgenium 111 161 272 Rg")); elements.Add(Atom.Parse("Hassium 108 169 277 Hs")); }

//#1 - Display all the items in the collection elements static void DisplayAllItems() { foreach (Atom a in elements) Console.WriteLine(a.ToString()); }

//#2 - Serialize the first item using json format and save to a suitable file static void SaveFirstItem() { string jsonString = JsonSerializer.Serialize(elements[0]);

TextWriter writer = new StreamWriter(FIRST_FILE);

writer.Write(jsonString);

writer.Close(); }

//#3 - Read the above file and display the item static void ReadItem() { TextReader reader = new StreamReader(FIRST_FILE);

Atom a = JsonSerializer.Deserialize(reader.ReadToEnd());

Console.WriteLine("--- ATOM READ FROM FILE:"); Console.WriteLine(a.ToString());

reader.Close(); }

//#4 - Serialize the entire collection using json format and save to a suitable file static void SaveAll() { // your implementation goes here }

//#5 - Read the above file and display all of the items static void ReadAll() { // your implementation goes here }

static void Main(string[] args) { AddAtoms();

//#1 DisplayAllItems();

//#2 SaveFirstItem();

//#3 ReadItem();

//#4 SaveAll();

//#5 ReadAll(); } } } ---=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-class---=-==--=-=-=-=-=

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace AtomApp { public class Atom { public string Name { get; set; } public string Symbol { get; set; } public int Proton { get; set; } public int Neutron { get; set; } public double Weight { get; set; }

public Atom() {

}

public Atom(string name, int proton, int neutron, double weight, string symbol) { Name = name; Proton = proton; Neutron = neutron; Weight = weight; Symbol = symbol; }

public static Atom Parse(string objectData) { string[] parts = objectData.Split();

Atom a = new Atom();

if (parts.Length != 5) throw new Exception("Line doesn't have 5 parts!"); else { a.Name = parts[0]; a.Proton = int.Parse(parts[1]); a.Neutron = int.Parse(parts[2]); a.Weight = double.Parse(parts[3]); a.Symbol = parts[4]; }

return a; }

public override string ToString() { return $"Element Name: {Name}, Element Symbol: {Symbol}, Protons: {Proton}, Neutrons: {Neutron}"; } } }

Your task is to implement the two missing methods "SaveAll()" and "ReadAll()". Details: SaveAll() - Serialize the entire collection using JSON format and save to the file set in the ALL_FILE constant. ReadAll() - Reads the file that was saved during SaveAll() and display all of the items in the console. Once you are done, copy and paste the code for each one of these 2 methods within the answer box below. Important: Don't modify anything else in the program, including the Main() method. Your task is to implement the two missing methods "SaveAll()" and "ReadAll()". Details: SaveAll() - Serialize the entire collection using JSON format and save to the file set in the ALL_FILE constant. ReadAll() - Reads the file that was saved during SaveAll() and display all of the items in the console. Once you are done, copy and paste the code for each one of these 2 methods within the answer box below. Important: Don't modify anything else in the program, including the Main() method

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!