Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C# Program Question: Create console application called CentennialFlowers . You have been provided with: a content of Orders.cs file that contain the source code for

C# Program Question:

Create console application called CentennialFlowers.

You have been provided with:

  • a content of Orders.cs file that contain the source code for the Orders class and Status enumeration.
  • Content of Program.cs file that contains unfinished code.

You will have to complete 3 steps.

Step 1:

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

Step 2:

  • Finish the SaveAllOrders method. This method is incomplete, and it should save the list of all orders from the parameter as a JSON file.
  • 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:

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

IMPORTANT: Dont modify that code in the Main() that has been provided. The output should match exactly the image below:

Once you are done, paste the code for each one of the steps in the box below. In the last test question, you will submit the whole solution with this and all other projects in this test.

Content of Orders.com:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CentennialFlowersJson { //order status enum enum Status { Paid, Unpaid, Cancelled } class Order { private int orderNumber; private string customerName; private string arrangement; private int quantity; private double unitPrice; private Status status; public int OrderNumber { get { return orderNumber; } set { orderNumber = value; } } public string CustomerName { get { return customerName; } set { customerName = value; } } public string Arrangement { get { return arrangement; } set { arrangement = value; } } public int Quantity { get { return quantity; } set { quantity = value; } } public double UnitPrice { get { return unitPrice; } set { unitPrice = value; } } public Status Status { get { return status; } set { status = value; } } public double TotalPrice { get { return quantity * unitPrice; } } public Order() { Quantity = 0; UnitPrice = 0; } } } Content of Program.cs:
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; } } }

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

Database Marketing The New Profit Frontier

Authors: Ed Burnett

1st Edition

0964535629, 978-0964535626

More Books

Students also viewed these Databases questions