Please fill out 1 -8. What will the code line look like for 1 - 8? Code is parti
ID: 3873280 • Letter: P
Question
Please fill out 1 -8. What will the code line look like for 1 - 8? Code is partially written. Program is done in C#.
{
public partial class FormStudentSignUpForPresentationSlot : Form
{
private ScheduleStudentPresentationController controller;
private Section selectedSection;
public FormStudentSignUpForPresentationSlot()
{
InitializeComponent();
//***********************************************************************
// 1.
//Instantiate an instance of the ScheduleStudentPresentationController
// and assign it to the class variable named "controller"
//***********************************************************************
//controller = ...
}
private void buttonGetSection_Click(object sender, EventArgs e)
{
// Clear out any residual info
labelSectionInfo.Text = "";
int studentId = 1;
//***********************************************************************
// 2.
// Use the variable that contains an instance of ScheduleStudentPresentationController
// to get the section. You will need to pass that method a studentId.
// Use the studentId variable defined above as the parameter
//***********************************************************************
//Section section = ...
//***********************************************************************
// 3.
// Now assign the returned Section to the class variable named "section"
//***********************************************************************
//selectedSection = ...
//***********************************************************************
// 4.
// Finally, set the labelSectionInfo's Text property to the concatenated
// attributes from the selected section. Use the coursePrefix, courseNumber,
// and sectionDescr properties with a space between each property
//***********************************************************************
//labelSectionInfo.Text = ...
}
private void buttonGetAvailableSlots_Click(object sender, EventArgs e)
{
// Clear out any residual info
listBoxAvailableSlots.Items.Clear();
// Simulate a database primary key for the selected section
int selectedSectionId = 1;
// Create an ojbect reference variable to hold the available slots
Dictionary<DateTime, List<Slot>> availableSlots = new Dictionary<DateTime, List<Slot>>();
//***********************************************************************
// 5.
// Use the variable that contains an instance of ScheduleStudentPresentationController
// to get the available slots. Use the previously defined selectedSectionId as the
// parameter
//***********************************************************************
//availableSlots = ...
listBoxAvailableSlots.Items.Add("Presentation Date # slots");
string availableDate = "";
int numAvailableSlots = 0;
foreach (KeyValuePair<DateTime,List<Slot>> item in availableSlots)
{
//***********************************************************************
// 6.
// Use the key to initialize the availableDate variable. Also, use the
// ToString("MM/dd/yyy") method to format the DateTime correclty.
//***********************************************************************
//availableDate = ...
//***********************************************************************
// 7.
// Use the value's count property to initialize the numAvailableSlots
// variable.
//***********************************************************************
//numAvailableSlots = ...
listBoxAvailableSlots.Items.Add(availableDate
+ " "
+ numAvailableSlots.ToString());
}
}
private void buttonSelectSlot_Click(object sender, EventArgs e)
{
int sectionId = 1;
int studentId = 1;
DateTime slotDate = dateTimePickerSlotDate.Value;
int slotNum = (int) numericUpDownSlotNumber.Value;
bool isSuccessful = false;
//***********************************************************************
// 8.
// Use the variable that contains an instance of ScheduleStudentPresentationController
// to indicate the selected slot. Capture the result in the isSeccessful variable.
// Use the variables (see above) sectionId, studentId, slotDate and slotNum as parameters.
//***********************************************************************
//isSuccessful = ...
labelSelectSlotSuccess.Text = isSuccessful.ToString();
if (isSuccessful) {
// Refresh the listbox due to reduction in available slots
buttonGetAvailableSlots_Click(this, new EventArgs());
}
}
private void FormStudentSignUpForPresentationSlot_Load(object sender, EventArgs e)
{
this.CenterToScreen();
}
private void FormStudentSignUpForPresentationSlot_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
this.Hide();
}
}
}
Explanation / Answer
public partial class FormStudentSignUpForPresentationSlot : Form
{
private ScheduleStudentPresentationController controller;
private Section selectedSection;
public FormStudentSignUpForPresentationSlot()
{
InitializeComponent();
//***********************************************************************
// 1.
//Instantiate an instance of the ScheduleStudentPresentationController
// and assign it to the class variable named "controller"
//***********************************************************************
//controller = ...
controller=new ScheduleStudentPresentationController();
}
private void buttonGetSection_Click(object sender, EventArgs e)
{
// Clear out any residual info
labelSectionInfo.Text = "";
int studentId = 1;
//***********************************************************************
// 2. & 3.
// Use the variable that contains an instance of ScheduleStudentPresentationController
// to get the section. You will need to pass that method a studentId.
// Use the studentId variable defined above as the parameter
//***********************************************************************
//Please replace the MethodName with the Name you intend in the comment
Section section=controller.MethodName(studentId);
//Merging point 2 & 3. I think the section should be selectedSectio, use replace section with selectedSection.
//BUT, If it's section indeed, then keep the code as it is.
// 4.
// Finally, set the labelSectionInfo's Text property to the concatenated
// attributes from the selected section. Use the coursePrefix, courseNumber,
// and sectionDescr properties with a space between each property
//***********************************************************************
//labelSectionInfo.Text = ...
labelSectionInfo.Text=section.coursePrefix+" "+section.courseNumber+" "+section.sectionDescr;
}
private void buttonGetAvailableSlots_Click(object sender, EventArgs e)
{
// Clear out any residual info
listBoxAvailableSlots.Items.Clear();
// Simulate a database primary key for the selected section
int selectedSectionId = 1;
// Create an ojbect reference variable to hold the available slots
Dictionary<DateTime, List<Slot>> availableSlots = new Dictionary<DateTime, List<Slot>>();
//***********************************************************************
// 5.
// Use the variable that contains an instance of ScheduleStudentPresentationController
// to get the available slots. Use the previously defined selectedSectionId as the
// parameter
//***********************************************************************
//Please replace the MethodName with the Name you intend in the comment
availableSlots = controller.MethodName(selectedSectionId);
listBoxAvailableSlots.Items.Add("Presentation Date # slots");
string availableDate = "";
int numAvailableSlots = 0;
foreach (KeyValuePair<DateTime,List<Slot>> item in availableSlots)
{
//***********************************************************************
// 6.
// Use the key to initialize the availableDate variable. Also, use the
// ToString("MM/dd/yyy") method to format the DateTime correclty.
//***********************************************************************
availableDate = item.key.ToString("MM/dd/yyy");
//***********************************************************************
// 7.
// Use the value's count property to initialize the numAvailableSlots
// variable.
//***********************************************************************
numAvailableSlots = item.value.Count;
listBoxAvailableSlots.Items.Add(availableDate
+ " "
+ numAvailableSlots.ToString());
}
}
private void buttonSelectSlot_Click(object sender, EventArgs e)
{
int sectionId = 1;
int studentId = 1;
DateTime slotDate = dateTimePickerSlotDate.Value;
int slotNum = (int) numericUpDownSlotNumber.Value;
bool isSuccessful = false;
//***********************************************************************
// 8.
// Use the variable that contains an instance of ScheduleStudentPresentationController
// to indicate the selected slot. Capture the result in the isSeccessful variable.
// Use the variables (see above) sectionId, studentId, slotDate and slotNum as parameters.
//***********************************************************************
//Please replace the MethodName with the Name you intend in the comment
isSuccessful = controller.MethodName(sectionId,studentId,slotDate,slotNum);
labelSelectSlotSuccess.Text = isSuccessful.ToString();
if (isSuccessful) {
// Refresh the listbox due to reduction in available slots
buttonGetAvailableSlots_Click(this, new EventArgs());
}
}
private void FormStudentSignUpForPresentationSlot_Load(object sender, EventArgs e)
{
this.CenterToScreen();
}
private void FormStudentSignUpForPresentationSlot_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
this.Hide();
}
}
}