Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C# Window Form Application I am trying to add exceptions: if the user doesn\'t e

ID: 3680181 • Letter: C

Question

C# Window Form Application

I am trying to add exceptions:

if the user doesn't enter anything in the textbox's.

a number in the last or first name Textboxes.

a letter in the GPA Textbox.

(Methods and Arrays need to be the same or atleast be represented)

CODE BELOW:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace VeryOwnApplication
{
public partial class studentGpaForm : Form
{
String[] lastname = new String[10];
String[] firstname = new String[10];
double[] gpa = new double[10];
String[] combodisplay = new String[10];
static int i = 0;

public studentGpaForm()
{
InitializeComponent();
}
private void addButton_Click(object sender, EventArgs e)
{
try
{

if (lastNameTextBox.Text != "")
{
lastname[i] = lastNameTextBox.Text;
}
else
{
lastNameTextBox.Focus();
}

if (firstNameTextBox.Text != "")
{
firstname[i] = firstNameTextBox.Text;
}
else
{
firstNameTextBox.Focus();
}
if (gpaTextBox.Text != "")
{
gpa[i] = Convert.ToDouble(gpaTextBox.Text);
}
else
{
gpaTextBox.Focus();
}

combodisplay[i] = lastname[i] + " " + firstname[i] + " " + gpa[i];
i++;

lastNameTextBox.Text = "";
firstNameTextBox.Text = "";
gpaTextBox.Text = "";
lastNameTextBox.Focus();

studentInfoComboBox.DataSource = null;
studentInfoComboBox.DataSource = combodisplay;
studentInfoComboBox.SelectedIndex = 0;
}

catch // Syntax errors, if a whole number is not entered
{
MessageBox.Show("Please enter a whole number.");
}
}

private void classAverageButton_Click(object sender, EventArgs e)
{
double av = 0, sum = 0;

for (int j = 0; j < i; j++)
{
sum = sum + gpa[j];
}
av = sum / i;
classAverageLabel.Text = av.ToString();
}

private void clearButton_Click(object sender, EventArgs e)
{
studentInfoComboBox.DataSource = null;
Array.Clear(combodisplay, 0, i);
i = 0;
lastNameLabel.Text = "";
firstNameLabel.Text = "";
gpaLabel.Text = "";
classAverageLabel.Text = "";
}

private void studentInfoComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (studentInfoComboBox.SelectedIndex > -1)
{
int index = studentInfoComboBox.SelectedIndex;
lastNameLabel.Text = lastname[index];
firstNameLabel.Text = firstname[index];
gpaLabel.Text = gpa[index].ToString();
}
}

private void exitButton_Click(object sender, EventArgs e)
{
this.Close();
}
}
}

Explanation / Answer

plz go throught the below link and download then run the application.Plz let me know your comments.

http://we.tl/NvQdrCpVDK