Answer to Question #319082 in C# for madhu

Question #319082

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:

 +AddToStock(Furniture []) : int
    
 +TotalStockValue(Furniture []) : double
     
  +ShowStockDetails(Furniture []) : int
     

The program should also contain definitions for class types as suggested below:

  +Furniture : class
    

  + BookShelf : class
    
  + DiningTable : class

1
Expert's answer
2022-03-27T16:36:27-0400
internal class Program
    {
        public class Furniture
        {
            public double Price { get; set; }
            public string Designation { get; set; }
            public Furniture()
            {


            }
        }
        public class BookShelf : Furniture
        {
            public BookShelf()
            {
                Price = 150;
                Designation = "Oak Shelf";
            }
        }
        public class DiningTable : Furniture
        {
            public DiningTable()
            {
                Price = 250;
                Designation = "Pine table";
            }
        }
        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)
        {
            double totalStockValue = 0;
            foreach (var furniture in furnitures)
            {
                totalStockValue += furniture.Price;
            }


            return totalStockValue;
        }


        public static void ShowStockDetails(List<Furniture> furnitures)
        {
            Console.WriteLine("Your stock:");
            foreach (Furniture furniture in furnitures)
            {
                Console.WriteLine($"Designation: {furniture.Designation} Prise: {furniture.Price}\n");
            }
            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