Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The application attached is called CentennialFlowers and you will be applying your knowledge about Serialization and JSON . You have been provided with a project

The application attached is called CentennialFlowers and you will be applying your knowledge about Serialization and JSON.

You have been provided with a project that you need to finish. It can be found within the provided ZIP file called CentennialFlowers.zip:

using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Console;

namespace CentennialFlowersJson { class Program { const string FILE_NAME = "Orders.json";

static void Main(string[] args) { //create a list of flower orders List orders = new List();

orders.Add(new Order { OrderNumber = 1125, CustomerName = "Peter Parker", Arrangement = "Flower Crown", Quantity = 5, UnitPrice = 50.00, Status = Status.Cancelled });

orders.Add(new Order { OrderNumber = 1126, CustomerName = "Mary Jane", Arrangement = "Rose Bouquet", Quantity = 2, UnitPrice = 100.00, Status = Status.Paid });

orders.Add(new Order { OrderNumber = 1127, CustomerName = "Aunt May", Arrangement = "Vertical Flower", Quantity = 3, UnitPrice = 55.00, Status = Status.Unpaid });

orders.Add(new Order { OrderNumber = 1128, CustomerName = "J.J Jameson", Arrangement = "Small Bouquet", Quantity = 2, UnitPrice = 65.00, Status = Status.Paid });

//save order list to file SaveAllOrders(orders);

//read order list from file List newOrders = ReadPaidOrders();

double totalPriceSum = 0;

WriteLine("---------------------------------------------------------------------------------"); WriteLine(" LIST OF PAID ORDERS"); WriteLine("---------------------------------------------------------------------------------"); //header Write($" {"Order #",-10}"); Write($"{"Customer Name",-20}"); Write($"{"Arrangement",-15}"); Write($"{"Quant",5}"); Write($"{"Unit Price",15}"); WriteLine($"{"Total Price",15}");

WriteLine("---------------------------------------------------------------------------------");

foreach (Order o in newOrders) { Write($" {o.OrderNumber,-10}"); Write($"{o.CustomerName,-20}"); Write($"{o.Arrangement,-15}"); Write($"{o.Quantity,5}"); Write($"{o.UnitPrice,15:c}"); WriteLine($"{o.TotalPrice,15:c}");

totalPriceSum += o.TotalPrice; }

WriteLine("---------------------------------------------------------------------------------"); WriteLine($" Total Number of Paid Orders: {newOrders.Count}"); WriteLine($" Total Price: {totalPriceSum:c}"); WriteLine("---------------------------------------------------------------------------------"); }

//this method is saving the orders list static void SaveAllOrders(List orders) { TextWriter writer = new StreamWriter(FILE_NAME);

foreach (Order o in orders) { //1 - missing this line

writer.WriteLine(jsonString); }

//2 - missing this line }

//this method is reading the orders and returning only the paid ones many orders static List ReadPaidOrders() { List orders = new List();

// implement your code here. // tips: //- read the file //- loop through the orders //- select the ones that match your condition //- populate the list //- close the file

return orders; } } }

The application is unfinished, and you will have to complete 3 steps. You should paste all 3 of them in the answer box below.

Step 1:

  • [2] Add the correct namespace so that JSON Serializer can work properly.

Step 2:

  • [5] Finish the SaveAllOrders method. This method is incomplete, and it should save the list of all orders from the parameter as a JSON file.
  • [2] Then close the file.

Step 3:

Implement the ReadPaidOrders method. There is very little code in this method, and you need to fully implement it to return the selected orders as a list. Below you can see the details of how this method should work:

  • [4] Read the list of orders from the JSON file saved by the SaveAllOrders method. Ensure to use the FILE_NAME constant for this.
  • [4] Loop through the orders;
  • [3] Select the orders that match the condition where the Status property is set to Paid.
  • [3] Populate the orders list.
  • [2] Close the file.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

C++ Database Development

Authors: Al Stevens

1st Edition

1558283579, 978-1558283572

More Books

Students also viewed these Databases questions

Question

=+e. If one person is selected at random from this region,

Answered: 1 week ago

Question

Finding and scheduling appointments with new prospective clients.

Answered: 1 week ago