Answer to Question #319807 in C# for Madhu

Question #319807

Calculate total stock value of the stock available in a furniture shop.

This program simulate the stock management of a Furniture Shop. This shop deals with only two type of Furnitures BookShelf and DiningTable only. The program should accept details any 5 furnitures(each can be either BookShelf or DiningTable), the program should show a menu that allow the user to select choice of Furniture. After accepting the required no of Furniture details program will show accepted details and TotalCost of Accepted Stock

This exercise contains a base class named Furniture to hold the common properties of all type of Furnitures, and BookShelf and DiningTable class as child class with additional properties relevant to child classes. Program class has below functions:

ddToStock(Furniture []) : int
    
 +TotalStockValue(Furniture []) : double
     
  +ShowStockDetails(Furniture []) : int
     
+Furniture : class
+ BookShelf : class
+ DiningTable : class




1
Expert's answer
2022-03-28T16:11:04-0400
internal class Program
    {
        public class Furniture
        {
            public double Price { get; set; }
            public string Name { get; set; }
            public string Color { get; set; }
            public string Material { get; set; }
            public Furniture()
            {


            }
            public override string ToString()
            {
                return $"Designation: {Name}, Material: {Material}, Color: {Color}, Prise: {Price};\n";
            }
        }
        public class BookShelf : Furniture
        {
            public BookShelf()
            {
                Price = 100;
                Name = "Shelf";
                Color = "White";
                Material = "Pine";
            }
        }
        public class DiningTable : Furniture
        {
            public DiningTable()
            {
                Price = 200;
                Name = "Table";
                Color = "Brown";
                Material = "Oak";
            }
        }
        static void Main(string[] args)
        {
            List<Furniture> furnitures = new List<Furniture>();
            AddToStock(furnitures);
            ShowStockDetails(furnitures);
            Console.ReadKey();
        }


        public static void AddToStock(List<Furniture> furnitures)
        {
            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine("Choose what furniture you want to stock: \n" +
                                "1.Dinning table \n" +
                                "2.Book Shelf \n" +
                                "3.Finish stock \n");
                Console.Write("Your choice: ");
                int choise = int.Parse(Console.ReadLine());
                if (choise == 1)
                    furnitures.Add(new DiningTable());
                else if (choise == 2)
                    furnitures.Add(new BookShelf());
                else
                    break;
                Console.Clear();
            }
            Console.Clear();
        }
        public static double TotalStockValue(List<Furniture> furnitures)
        {
            return furnitures.Sum(f => f.Price);
        }


        public static void ShowStockDetails(List<Furniture> furnitures)
        {
            Console.WriteLine("Your stock:");
            foreach (Furniture furniture in furnitures)
            {
                Console.WriteLine(furniture.ToString());
            }
            Console.WriteLine($"Total stock value: {TotalStockValue(furnitures)}");
        }


    }

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