Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help on my assignment. Below are the instructions and below the instructions are my current code Using Assignment 2, add both Data Validation

I need help on my assignment. Below are the instructions and below the instructions are my current code

Using Assignment 2, add both Data Validation and Exception handling.

Make sure to handle at least 1 specific exception and the generic exception in each button. Try to make the specific exception applicable to the task. For instance, don't use DivideByZeroException for the multiplication button as this can't occur doing multiplication.

Put your Data Validation into methods. How you choose to call the methods is up to you.

I'll upload a starting point (completed assignment 2) on Friday night (Feel free to use yours and start sooner). Please make sure your assignment 2 is turned in before then or else you will receive a zero for that assignment.

Turn in the zip folder of the project and a screen shot of the project catching an exception or the Data Validation preventing an exception.

namespace Assignment2Morris { public partial class Form1 : Form { double FirstNumber; string Operation; public Form1() { InitializeComponent(); }

private void Form1_Load(object sender, EventArgs e) {

} //showing how to make the "3" button function private void button8_Click(object sender, EventArgs e) { if (textBox1.Text == "0" && textBox1.Text != null) { textBox1.Text = "3"; } else { textBox1.Text = textBox1.Text + "3"; } } //showing how to make the "8" button function private void button11_Click(object sender, EventArgs e) { if (textBox1.Text == "0" && textBox1.Text != null) { textBox1.Text = "8"; } else { textBox1.Text = textBox1.Text + "8"; } }

//showing how to make the "1" button function private void btn1_Click(object sender, EventArgs e) { if (textBox1.Text == "0" && textBox1.Text != null) { textBox1.Text = "1"; } else { textBox1.Text = textBox1.Text + "1"; } } //showing how to make the "2" button function private void btn2_Click(object sender, EventArgs e) { if (textBox1.Text == "0" && textBox1.Text != null) { textBox1.Text = "2"; } else { textBox1.Text = textBox1.Text + "2"; } } //showing how to make the "4" button function private void btn4_Click(object sender, EventArgs e) { if (textBox1.Text == "0" && textBox1.Text != null) { textBox1.Text = "4"; } else { textBox1.Text = textBox1.Text + "4"; } } //showing how to make the "5" button function private void btn5_Click(object sender, EventArgs e) { if (textBox1.Text == "0" && textBox1.Text != null) { textBox1.Text = "5"; } else { textBox1.Text = textBox1.Text + "5"; } } //showing how to make the "6" button function private void btn6_Click(object sender, EventArgs e) { if (textBox1.Text == "0" && textBox1.Text != null) { textBox1.Text = "6"; } else { textBox1.Text = textBox1.Text + "6"; } } //showing how to make the "7" button function private void btn7_Click(object sender, EventArgs e) { if (textBox1.Text == "0" && textBox1.Text != null) { textBox1.Text = "7"; } else { textBox1.Text = textBox1.Text + "7"; } } //showing how to make the "9" button function private void btn9_Click(object sender, EventArgs e) { if (textBox1.Text == "" && textBox1.Text != null) { textBox1.Text = "9"; } else { textBox1.Text = textBox1.Text + "9"; } } //showing how to make the "0" button function private void btn0_Click(object sender, EventArgs e) { textBox1.Text = textBox1.Text + "0";

} //showing how to make the "=" button function private void btnAdd_Click(object sender, EventArgs e) { FirstNumber = Convert.ToDouble(textBox1.Text); textBox1.Text = "0"; Operation = "+"; } //showing how to make the "-" button function private void btnSub_Click(object sender, EventArgs e) { FirstNumber = Convert.ToDouble(textBox1.Text); textBox1.Text = "0"; Operation = "-"; } //showing how to make the "*" button function private void btnMultiply_Click(object sender, EventArgs e) { FirstNumber = Convert.ToDouble(textBox1.Text); textBox1.Text = "0"; Operation = "*"; } //showing how to make the "/" button function private void btnDivide_Click(object sender, EventArgs e) { FirstNumber = Convert.ToDouble(textBox1.Text); textBox1.Text = "0"; Operation = "/"; } //showing how to make the "C" button function private void btnClear_Click(object sender, EventArgs e) { textBox1.Text = "0"; } //showing how to make the "." button function private void btnDot_Click(object sender, EventArgs e) { textBox1.Text = textBox1.Text + "."; } //showing how to program the equal button (didn't use pseudocode //beforehand to lay out exactly what needed to happen and this really gave me trouble) private void button6_Click(object sender, EventArgs e) { double SecondNumber; double Result;

SecondNumber = Convert.ToDouble(textBox1.Text);

if (Operation == "+") { Result = (FirstNumber + SecondNumber); textBox1.Text = Convert.ToString(Result); FirstNumber = Result; } if (Operation == "-") { Result = (FirstNumber - SecondNumber); textBox1.Text = Convert.ToString(Result); FirstNumber = Result; } if (Operation == "*") { Result = (FirstNumber * SecondNumber); textBox1.Text = Convert.ToString(Result); FirstNumber = Result; } if (Operation == "/") { if (SecondNumber == 0) { textBox1.Text = "Cannot divide by zero";

} else { Result = (FirstNumber / SecondNumber); textBox1.Text = Convert.ToString(Result); FirstNumber = Result; } } } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions

Question

Describe the six principles of persuasion.

Answered: 1 week ago

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago