Calculate total stock value of the stock available in a furnitur
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
-
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 = "Pine Shelf";
}
}
public class DiningTable : Furniture
{
public DiningTable()
{
Price = 250;
Designation = "Oak 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: ");
switch(Console.ReadLine())
{
case "1":
{
furnitures.Add(new DiningTable());
break;
}
case "2":
{
furnitures.Add(new BookShelf());
break;
}
default:
{
i = 5;
break;
}
}
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($"Designation: {furniture.Designation}, Prise: {furniture.Price};\n");
}
Console.WriteLine($"Total stock value: {TotalStockValue(furnitures)}");
}
}
Comments
Leave a comment