Классы и объекты ООП и их методы - C#
Формулировка задачи:
Необходимо разработать класс на тему "Меню в кафе", а также метод, например, который рассчитывает стоимость что-либо в кафе. Помогите плиз, пытался через консоль все это сделать, не получается
Ну вот типа того:
{
private string brand;
private string color;
private int power;
private int maxSpeed;
private int volumeOfTank;
private double fuelConsumption;
}
public class Car
{
private string brand;
private string color;
private int power;
private int maxSpeed;
private int volumeOfTank;
private double fuelConsumption;
//конструктор класса
public Car(string newBrand, string newColor, int newPower, int newMaxSpeed,
int newVolumeOfTank, double newFuelConsumption)
{
brand = newBrand;
color = newColor;
power = newPower;
maxSpeed = newMaxSpeed;
volumeOfTank = newVolumeOfTank;
fuelConsumption = newFuelConsumption;
}
}
public class Car
{
private string brand;
private string color;
private int power;
private int maxSpeed;
private int volumeOfTank;
private double fuelConsumption;
//конструктор класса
public Car(string newBrand, string newColor, int newPower, int newMaxSpeed,
int newVolumeOfTank, double newFuelConsumption)
{
brand = newBrand;
color = newColor;
power = newPower;
maxSpeed = newMaxSpeed;
volumeOfTank = newVolumeOfTank;
fuelConsumption = newFuelConsumption;
}
}
Car c = new Car("Ford", "Серый", 150, 210, 55, 6.4);
{
double quantity = 100 * volumeOfTank / fuelConsumption;
return quantity;
}Решение задачи: «Классы и объекты ООП и их методы»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ClassMenu
{
enum Type_product_of_menu {Food = 1, Drink = 2};
public class ClassMenu
{
private static int currentId;
private string name;
private int size;
private int id;
private decimal price;
private Type_product_of_menu type_product_of_menu;
public ClassMenu(string name, decimal price, int type, int size)
{
this.price = price;
this.name = name;
this.type_product_of_menu = (Type_product_of_menu)type;
this.size = size;
this.id = currentId++;
}
public decimal Get_price()
{
return price;
}
public void Set_name(string name)
{
this.name = name;
}
public override string ToString()
{
return String.Format("{0} {1} {2} {3} {4}", this.name , this.price, this.type_product_of_menu, this.size, this.id) ;
}
}
class Program
{
static void Main(string[] args)
{
List<ClassMenu> menu = new List<ClassMenu>();
menu.Add(new ClassMenu("Pork", 123, 1, 250));
Console.WriteLine(menu[0]);
menu[0].Set_name("Lamb");
Console.WriteLine(menu[0]);
Console.ReadKey();
}
}
}