Edited
This my IAnimal Interface
interface IAnimal
{
string getName();
int getAge();
bool getGender();
void eat();
}
This is my IWalk Interface
interface IWalk
{
void walk();
}
This is my IBird Interface
interface IBird : IAnimal, IWalk
{
}
This is my IFlightless_bird Intreface
interface IFlightless_bird : IBird
{
}
This is my Iswim Interface
interface ISwim
{
void swim();
}
This is my King_penguin Class
public sealed class King_penguin : IFlightless_bird, ISwim
{
private string name;
private int age;
private bool gender;
public King_penguin(string name, int age, bool gender)
{
this.name = name;
this.age = age;
this.gender = gender;
}
public string getName()
{
return this.name;
}
public int getAge()
{
return this.age;
}
public bool getGender()
{
return this.gender;
}
public void eat()
{
Debug.WriteLine("I ate!");
}
public void walk()
{
Debug.WriteLine("I walked!");
}
public void swim()
{
Debug.WriteLine("I swam!");
}
}
I have a dropdown which is filled with strings which have exactly the same name as all my animal classes. 1
This is the Code of the StartForm Form
public partial class StartForm : Form
{
public StartForm()
{
InitializeComponent();
}
private void btnCreateAnimal_Click(object sender, EventArgs e)
{
string selected = comboBoxAnimal.SelectedItem.ToString();
Debug.WriteLine(selected);
var createAnimal = new CreateAnimalForm(selected);
createAnimal.Show(this);
}
}
When I have selected the animal, I want to define the parameters that are required by the constructor. 2
This is the code of the CreateAnimalForm Form
public partial class CreateAnimalForm : Form
{
string animal;
public CreateAnimalForm(string animal)
{
this.animal = animal;
InitializeComponent();
}
private void btnCreateAnimal_Click(object sender, EventArgs e)
{
bool gender;
string name = textBoxName.ToString();
int age = int.Parse(textBoxAge.Text);
if (radioButtonMale.Checked)
{
gender = true;
}
else
{
gender = false;
}
IAnimal AnyAnimal = new this.animal(name, age, gender);
}
}
When I have defined the parameters, I want to be able to press the button and create an object using the defined parameters and the selected animal