Answer to Question #256612 in C# for mack

Question #256612
You will need to complete the following objectives as a C# Windows Form Application: 1. When the program starts the user needs to be asked if they want to make a new entry or to view a previous entry 2. If the user wants to make a new entry, the first question will be how many meters they travelled (this will then need to be converted into kilometers) 3. The second question will give the user 3 options to choose from, and each option will have a value. The options are as follows: a. Hatchback = 3 b. SUV = 3.5 c. Sports car = 4. When the user has selected an option that options value needs to be multiplied by the distance they travelled in kilometers 4. The third question will allow the user to entera description, of where they travel to and why did they travel there. 5. All the information above needs to then be saved into a JSON file 6. If the user says he want to view a previous entry the JSON file needs to be loaded and displayed.
1
Expert's answer
2021-10-26T09:14:51-0400
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
 
namespace Conditional
{
    class SwitchCase
    {
        public static void Main(string[] args)
        {
            int choice, distance;
            double a, result;
            char option;
            string description;
             
            Console.Write("Do you want to make a new entry or to view a previous entry[0, 1]: ");
            choice = Convert.ToInt32(Console.ReadLine());
            
            if (choice == 0) {
                Console.Write("how many meters have you travelled: ");
                distance = Convert.ToInt32(Console.ReadLine());
                
                Console.Write("Select one:\na. Hatchback = 3\nb. SUV = 3.5\nc. Sports car = 4");
                option = (char)Console.Read();
                switch (option) {
                    case 'a': result = 3 * distance / 1000; break;
                    case 'b': result = 3.5 * distance / 1000; break;
                    case 'c': result = 4 * distance / 1000; break;
                }
                
                Console.Write("Enter a description: ");
                description = Console.ReadLine();
                List<data> _data = new List<data>();
                _data.Add(new data()
                {
                    Distance = distance,
                    description = description
                });
                
                string json = JsonSerializer.Serialize(_data);
                File.WriteAllText(@".\path.json", json);
            }
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS