ok so i have to make a phone book using constructors properties and an array of objects and have been doing it for 12 hours straight i want to confirm im going down the right lines as i am unsure as to how i can test this at this time.
its a windows application with 3 input fields name, phone number and email address.
the person class contains the properties
the phone book should hold the array of objects but as far as i can tell doesnt and im not sure why.
Question
lost and confused
ok so i have to make a phone book using constructors properties and an array of objects and have been doing it for 12 hours straight i want to confirm im going down the right lines as i am unsure as to how i can test this at this time.
its a windows application with 3 input fields name, phone number and email address.
the person class contains the properties
the phone book should hold the array of objects but as far as i can tell doesnt and im not sure why.
private void addBtn_Click(object sender, EventArgs e)
{
string forename;
string phoneNumber;
string emailAddress;
forename = forenameTxt.Text;
phoneNumber = phoneNumTxt.Text;
emailAddress = emailAddressTxt.Text;
if (forenameTxt.Text != "" && phoneNumTxt.Text != "" && emailAddressTxt.Text != "")
{
person create = new person(forename, phoneNumber, emailAddress);
}
else
{
MessageBox.Show("Error: Not all values added!");
}
}
public person(string forename, string phoneNumber, string emailAddress)
{
_Forename = forename;
_PhoneNumber = phoneNumber;
_EmailAddress = emailAddress;
phonebook addContact = new phonebook(_Forename, _PhoneNumber, _EmailAddress);
}
public string Forename
{
get
{
return _Forename;
}
set
{
_Forename = value;
}
}
public string phoneNumber
{
get
{
return _PhoneNumber;
}
set
{
_PhoneNumber = value;
}
}
public string emailAddress
{
get
{
return _EmailAddress;
}
set
{
_EmailAddress = value;
}
}
}
public class phonebook
{
private string Forname;
private string PhoneNumber;
private string EmailAddress;
int contactCount = 0;
public phonebook(string forename, string phoneNumber, string emailAddress)
{
Forname = forename;
PhoneNumber = phoneNumber;
EmailAddress = emailAddress;
person[] addContact = new person[100];
for (int i = 0; i < 101; i++)
{
addContact[this.contactCount] = new person(Forname, PhoneNumber, EmailAddress);
}
}
}
}
Edited by lost and confusedLink to comment
Share on other sites
9 answers to this question
Recommended Posts