2015. 8. 15. 16:58, C#/Head First C# Practice
[설명]
고기, 빵, 소스를 랜덤하게 선택하여 메뉴를 만들어 봄으로써 배열을 연습
[실행화면]
[소스코드]
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 | 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 SloppyJoeMenu { public partial class Form1 : Form { public Form1() { InitializeComponent(); MenuMaker menu = new MenuMaker() { Randomizer = new Random() }; this .label1.Text = menu.GetMenuItem(); this .label2.Text = menu.GetMenuItem(); this .label3.Text = menu.GetMenuItem(); this .label4.Text = menu.GetMenuItem(); this .label5.Text = menu.GetMenuItem(); this .label6.Text = menu.GetMenuItem(); } public class MenuMaker { public Random Randomizer; string [] Meats = { "Roast beef" , "Salami" , "Turkey" , "Ham" , "Pastrami" }; string [] Condiments = { "yellow mustard" , "brown mustard" , "honey mustard" , "mayo" , "relish" , "french dressing" }; string [] Breads = { "rye" , "white" , "wheat" , "pumpernickel" , "italian bread" , "a roll" }; public string GetMenuItem() { string randomMeat = Meats[Randomizer.Next(Meats.Length)]; string randomCondiment = Condiments[Randomizer.Next(Condiments.Length)]; string randomBreads = Breads[Randomizer.Next(Breads.Length)]; return randomMeat + " with " + randomCondiment + " on " + randomBreads; } } } } |
'C# > Head First C# Practice' 카테고리의 다른 글
인스턴스의 속성을 맞바꾸기 (0) | 2015.08.15 |
---|---|
Mileage Calculator (0) | 2015.08.09 |
메서드를 만들 때 정적(static) 키워드를 사용하는 이유 (0) | 2015.08.09 |
ExchangeMoney, 돈 송수금 하기 (0) | 2015.08.09 |
Getting Start! 연습을 시작하며... (0) | 2015.08.09 |
Comments, Trackbacks