эТо автоматический рефакторинг as is:
using System;
using System.Windows.Forms;
namespace Proga1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public enum Eda
{
Pie,
IceCream,
Cookies
}
public interface IEda
{
string Info();
string Cost(int kolvokal);
}
public class DesertName : IEda
{
public Eda DesertType { get; private set; }
public string Name { get; private set; }
public int Year { get; private set; }
public string Producer { get; private set; }
public int ShelfLife { get; private set; }
public double Composition { get; private set; }
public DesertName(Eda desertType, string name, int year, string producer, int shelfLife, double composition)
{
DesertType = desertType;
Name = name;
Year = year;
Producer = producer;
ShelfLife = shelfLife;
Composition = composition;
}
public string Info()
{
return $"Тип десерта: {DesertType}\nНазвание: {Name}\nДата: {Year}\nПроизводитель: {Producer}\nСрок годности: {ShelfLife}\nСостав: {Composition}";
}
public string Cost(int kolvokal)
{
double totalCost = kolvokal * (int)DesertType;
return $"Количество калорий: {kolvokal}, общая стоимость: {totalCost}";
}
}
private void button1_Click(object sender, EventArgs e)
{
try
{
Eda selectedDesert = (Eda)comboBox1.SelectedIndex;
string name = textBox1.Text;
int year = dateTimePicker1.Value.Year;
string producer = textBox3.Text;
int shelfLife = int.Parse(textBox2.Text);
double composition = double.Parse(textBox4.Text);
DesertName desertName = new DesertName(selectedDesert, name, year, producer, shelfLife, composition);
label8.Text = desertName.Info();
}
catch (Exception ex)
{
MessageBox.Show($"Ошибка: {ex.Message}");
}
}
private void button2_Click(object sender, EventArgs e)
{
try
{
int calories = int.Parse(textBox5.Text);
label9.Text = desertName?.Cost(calories) ?? "Сначала выберите десерт";
}
catch (Exception ex)
{
MessageBox.Show($"Ошибка: {ex.Message}");
}
}
}
}
using System.ComponentModel;using System.Data;
using System.Drawing;using System.IO ;
using System.Linq;using System.Reflection.Emit;
using System.Text;using System.Threading.Tasks;
using System.Windows .Forms;using static System.Windows .Forms.VisualStyles.VisualStyleElement.Button;
using static System.Windows .Forms.VisualStyles.VisualStyleElement;
namespace Proga1{
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
public enum Eda {
Pie, IceCream,
Cookies }
public interface IEda {
string Info(); string Cost(int kolvokal);
} public class DesertName : IEda
{ protected Eda desert;
protected string nazvdesert; protected int data;
protected string proizvod; protected int srok;
protected int sostav; }
public DesertName(Eda desert, string nazvdesert, int data, string proizvod, int srok, int sostav,)
{
this.desert = desert; this.nazvdesert = nazvdesert;
this.data = data; this.proizvod = proizvod;
this.srok = srok; this.sostav = sostav;
}
public string Info()
{ return $"Тип дерева: {desert}\nВозраст: {nazvdesert} лет\nНаличие прививки: {data}\nСадовник: {proizvod}\nСтоимость посадки 1 дерева: {srok}\nСостав:{sostav}\nКолво кал{kolvolal}";
}
public string Cost(int kolvokal1)
{ double totalCost = kolvokal * desert;
return $"колличество каллорий {kolvokal1} равняеца {totalCost}"; }
}
DesertName desertName; private void button1_Click(object sender, EventArgs e)
{
desertName = new DesertName((desert)comboBox1.SelectedIndex, textBox1.Text,int.Parse(textBox2.Text), data , dateTimePicker1, double.Parse(textBox4.Text));
label8.Text = desertName.Info(); }
private void button2_Click(object sender, EventArgs e)
{ int a = int.Parse(textBox5.Text);
label9.Text = desertName.Cost(a); }
private void textBox4_TextChanged(object sender, EventArgs e)
{
}
}