Form1.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace DinnerParty { public partial class Form1 : Form { DinnerParty dinnerParty; public Form1() { InitializeComponent(); dinnerParty = new DinnerParty((int)numericUpDown1.Value,checkBox1.Checked, checkBox2.Checked); DisplayDinnerPartyCost(); } private void DisplayDinnerPartyCost() { decimal Cost = dinnerParty.Cost; label3.Text = Cost.ToString("c"); } private void numericUpDown1_ValueChanged(object sender, EventArgs e) { dinnerParty.NumberOfPeople = (int)numericUpDown1.Value; DisplayDinnerPartyCost(); } private void checkBox1_CheckedChanged(object sender, EventArgs e) { dinnerParty.FancyDecorations = checkBox1.Checked; DisplayDinnerPartyCost(); } private void checkBox2_CheckedChanged(object sender, EventArgs e) { dinnerParty.HealthyOption = checkBox2.Checked; DisplayDinnerPartyCost(); } } } | cs |
DinnerParty.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DinnerParty { class DinnerParty { public int NumberOfPeople { get; set; } public bool FancyDecorations { get; set; } public bool HealthyOption { get; set; } public decimal CostOfDecorations = 0; public const int CostOfFoodPerPerson = 25; public DinnerParty(int number,bool healthy,bool fancyDeco) { NumberOfPeople = number; FancyDecorations = fancyDeco; HealthyOption = healthy; } public decimal setHealthyOption() { decimal costOfbeverage; if (HealthyOption) { costOfbeverage = 5.00M; } else { costOfbeverage = 20.00M; } return costOfbeverage; } private decimal CalculateCostOfDecorations() { decimal costOfDeco; if (FancyDecorations) { costOfDeco = (NumberOfPeople * 15.00M) + 50M; } else { costOfDeco = (NumberOfPeople * 7.50M) + 30M; } return costOfDeco; } public decimal Cost { get{ decimal total = CalculateCostOfDecorations(); total += ((setHealthyOption() + CostOfFoodPerPerson) * NumberOfPeople); if(HealthyOption) { total *= .95M; } return total; } } } } |
'프로그래밍 > C#' 카테고리의 다른 글
c#기반의 네트워크 통신 예제 소스 모음 (0) | 2019.08.03 |
---|---|
(C#) get, set 접근자 (0) | 2016.07.09 |
(C#) Head First - 캡슐화 (0) | 2016.07.09 |
(C#) head first - MessageBox 사용 (0) | 2016.07.09 |
(C#) Head First - 경마 (0) | 2016.07.09 |