public ScreenBase defineScreen() { ScreenBase result = new ColorfulScreen(); Console.WriteLine("Choose screen type index:"); Console.WriteLine($"0 - {nameof(MonochromeScreen)}"); Console.WriteLine($"1 - {nameof(ColorfulScreen)}"); int screenType = Convert.ToInt32(Console.ReadLine()); if (screenType == 0) { result = new MonochromeScreen(); } if (screenType == 1) { Console.WriteLine("Choose ColorfulScreen type index:"); Console.WriteLine($"0 - {nameof(OLEDScreen)}"); Console.WriteLine($"1 - {nameof(RetinaScreen)}"); int colorfulScreenType = Convert.ToInt32(Console.ReadLine()); if (colorfulScreenType == 0) { result = new OLEDScreen(); } else if (colorfulScreenType == 1) { result = new RetinaScreen(); } } return(result); }
private void button1_Click(object sender, EventArgs e) { //1st group of radio-buttons (Speaker settings): VoiceOutput VoiceOutput = new VoiceOutput(); ISpeaker Speaker = null; if (IPhoneHeadset.Checked) { Speaker = new IphoneHeadset(VoiceOutput, "IphoneX", true); } else if (SamsungHeadset.Checked) { Speaker = new SamsungHeadset(VoiceOutput, "SamsungA", true); } else if (PhoneSpeaker.Checked) { Speaker = new PhoneSpeaker(VoiceOutput, "model-ABC"); } else { }; //there is an option not to select radio button without assertion error if (Speaker != null) { VoiceOutput.DataOutput("Speaker selected"); Speaker.Play(null); } else { VoiceOutput.DataOutput("Speaker is not selected"); } //2nd group of radio-buttons (Screen settings) TextOutput TextOutput = new TextOutput(); ScreenBase Screen = null; string screenType = null; if (MonochromeScreen.Checked) { Screen = new MonochromeScreen(TextOutput, 2.0, 200); screenType = nameof(MonochromeScreen); } else if (ColorfulScreen.Checked) { Screen = new ColorfulScreen(TextOutput, 7.0, 500, true); screenType = nameof(ColorfulScreen); } //there is an option not to select radio button without assertion error if (Screen != null) { textBox1.Text = "Set screen to Mobile... \n Selected screen is " + screenType; } else { textBox1.Text = "Screen is not selected"; } }
static void Main(string[] args) { IScreen Screen = new ColorfulScreen(7.0, "T24", 500, true); IBattery Battery = new Battery(2000, "Li-ion"); IKeyboard Keyboard = new Keyboard("Russian", "Samsung"); IMicrophone Microphone = new Microphone(94, "model-xxx0155"); ISpeaker Speaker = new SamsungHeadset("model-XXX", false); ISimCard SimCard = new SimCard(SimCardType.NanoSim, 1111); IMobile Samsung = new Mobile(Screen, Battery, Keyboard, Microphone, Speaker, SimCard); Console.WriteLine(Samsung.GetDescription()); Console.ReadLine(); }