Create an application with a class named PersonEntry. The PersonEntry class shou
ID: 3779318 • Letter: C
Question
Create an application with a class named PersonEntry. The PersonEntry class should have properties for a person s name, e-mail address, and phone number. Also, create a text file that contains the names, e-mail addresses, and phone numbers for at least five people. When the application starts, it should read the data from the file and create a PersonEntry object for each person's data. The PersonEntry objects should be added to a List, and each person's name should be displayed In a list box on the application's main form. When the user selects a name from the list box. a second form should appear displaying that person's name, e-mail address, and phone number.Explanation / Answer
{
class PersonEntry
{
//We're gonna need some variables/properties, and then we're making a constructor.
public string PersonName { get; set; } //Creates a variable for the person's name.
public string PersonEmail { get; set; } //Creates a variable for the person's email.
public string PersonPhone { get; set; } //Creates a variable for the person's phone number.
}
}
public class Form2 : Form
{
PersonEntry selectedEntry;
public Form2(PersonEntry entry)
{
selectedEntry = entry;
}
// Use selectedEntry to fill in the form.
}
private void MainForm_Load(object sender, EventArgs e)
{
//Clears anything currently in the Listbox.
namesListBox.Items.Clear();
}
private void getNamesButton_Click(object sender, EventArgs e)
{
//Field to hold a list of PersonEntry objects.
List<PersonEntry> nameList =
new List<PersonEntry>();
//Create an instance of the PersonEntry structure.
PersonEntry entry = new PersonEntry();
try
{
StreamReader sr = new StreamReader();
string line;
while (!sr.EndOfStream)
{
//namesListBox.Items.Add(line);
line = sr.ReadLine();
//Identify the delimiter.
char[] delim = { ',' };
//Tokenize the line.
string[] tokens = line.Split(delim);
//Store the tokens in the entry object.
entry.PersonName = tokens[0];
entry.PersonEmail = tokens[1];
entry.PersonPhone = tokens[2];
//Add the entry object to the List.
namesListBox.Items.Add(entry.PersonName);
}
}
catch (Exception ex)
{
MessageBox.Show("ERROR: YOU ARE A DUMBASS " + ex.Message);
}
}
public void namesListBox_SelectedIndexChanged(object sender, EventArgs e)
{
//int index = namesListBox.FindString(SelectedIndex.text);
//nameslistbox.SelectedIndex = index;
DetailForm f2 = new DetailForm(entry.PersonName, entry.PersonEmail, entry.PersonPhone);
f2.Show();
}
public string Transfer
{
get { return ToString(); }
//get { return (namesListBox)GetValue(SelectedEntryProperty); }
//set { SetValue(SelectedEntryProperty, value); }
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.