So in this c# code, there are commented sections with **** and numbers denoting
ID: 3873276 • Letter: S
Question
So in this c# code, there are commented sections with **** and numbers denoting which question to answer. Ive bolded the ones ive done, but im not sure if they are right. Please check my bolded code and let me know if its correct, and if not, alter it. These are very small snippets of code. This is not a coding class, so there is not much writing.
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace A4_Skeleton
{
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 = new ScheduleStudentPresentationController();
}
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 = controller.studentId;
//***********************************************************************
// 3.
// Now assign the returned Section to the class variable named "section"
//***********************************************************************
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 = selectedSection.coursePrefix+ " " + selectedSection.courseNumber + " " + selectedSection.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
//***********************************************************************
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();
}
private void listBoxAvailableSlots_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
Explanation / Answer
1) Correct instantiation
2) and 3) Combined: Instead of "Section section = controller.studentId; section = selectedSection;", use "Section section = controller.MethodOfControllerClassThatReturnsSection(studentId);
4)Correct concatenation of properties
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.