Question

In: Computer Science

Design an application that enables users to enter two values of type int. Write a method...

Design an application that enables users to enter two values of type int. Write a method that retrieves the values and stores them and their products in separate structures. If you are designing a Windows application, you might allow the user to input the values in a TextBox and then retrieve and store the values in a ListBox. Their product could be stored in a separate ListBox. Your solution should include exception-handling techniques with a minimum of two catch clauses.

This is one programming assignment on Error Handling and debugging. Students do not need to submit a separate project for each part, just the finished project. Please remember to include you commented out each "exception" that caused an error (there should be 4).

This is for C#

Solutions

Expert Solution

As per your requirement I have written code which fulfill all your requirements please follow it step by step and i have included comments for better understanding

FormApp.Designer.cs

namespace ValuesProduct
{
partial class FormApp
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.labelElement1 = new System.Windows.Forms.Label();
this.firstTextValue = new System.Windows.Forms.TextBox();
this.secondTextValue = new System.Windows.Forms.TextBox();
this.labelElement2 = new System.Windows.Forms.Label();
this.submitButton = new System.Windows.Forms.Button();
this.listTwoBoxValues = new System.Windows.Forms.ListBox();
this.listProductBox = new System.Windows.Forms.ListBox();
this.labelElement3 = new System.Windows.Forms.Label();
this.labelElement4 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// labelElement1
//
this.labelElement1.AutoSize = true;
this.labelElement1.Location = new System.Drawing.Point(90, 46);
this.labelElement1.Name = "labelElement1";
this.labelElement1.Size = new System.Drawing.Size(84, 13);
this.labelElement1.TabIndex = 0;
this.labelElement1.Text = "Enter First Value";
//
// firstTextValue
//
this.firstTextValue.Location = new System.Drawing.Point(180, 43);
this.firstTextValue.Name = "firstTextValue";
this.firstTextValue.Size = new System.Drawing.Size(100, 20);
this.firstTextValue.TabIndex = 1;
this.firstTextValue.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.keyPressFirstTextValue);
//
// secondTextValue
//
this.secondTextValue.Location = new System.Drawing.Point(180, 80);
this.secondTextValue.Name = "secondTextValue";
this.secondTextValue.Size = new System.Drawing.Size(100, 20);
this.secondTextValue.TabIndex = 3;
this.secondTextValue.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.keyPressSecondTextValue);
//
// labelElement2
//
this.labelElement2.AutoSize = true;
this.labelElement2.Location = new System.Drawing.Point(72, 83);
this.labelElement2.Name = "labelElement2";
this.labelElement2.Size = new System.Drawing.Size(102, 13);
this.labelElement2.TabIndex = 2;
this.labelElement2.Text = "Enter Second Value";
//
// submitButton
//
this.submitButton.Location = new System.Drawing.Point(180, 107);
this.submitButton.Name = "submitButton";
this.submitButton.Size = new System.Drawing.Size(75, 23);
this.submitButton.TabIndex = 4;
this.submitButton.Text = "Submit";
this.submitButton.UseVisualStyleBackColor = true;
this.submitButton.Click += new System.EventHandler(this.submitButtonClick);
//
// listTwoBoxValues
//


this.listTwoBoxValues.FormattingEnabled = true;
this.listTwoBoxValues.Location = new System.Drawing.Point(84, 165);
this.listTwoBoxValues.Name = "listTwoBoxValues";
this.listTwoBoxValues.Size = new System.Drawing.Size(99, 69);
this.listTwoBoxValues.TabIndex = 5;
//
// listProductBox
//


this.listProductBox.FormattingEnabled = true;
this.listProductBox.Location = new System.Drawing.Point(268, 165);
this.listProductBox.Name = "listProductBox";
this.listProductBox.Size = new System.Drawing.Size(99, 69);
this.listProductBox.TabIndex = 6;
//
// labelElement3
//


this.labelElement3.AutoSize = true;
this.labelElement3.Location = new System.Drawing.Point(81, 137);
this.labelElement3.Name = "labelElement3";
this.labelElement3.Size = new System.Drawing.Size(119, 13);
this.labelElement3.TabIndex = 7;
this.labelElement3.Text = "Store Enter Two Values";
//
// labelElement4
//
this.labelElement4.AutoSize = true;
this.labelElement4.Location = new System.Drawing.Point(262, 137);
this.labelElement4.Name = "labelElement4";
this.labelElement4.Size = new System.Drawing.Size(106, 13);
this.labelElement4.TabIndex = 8;
this.labelElement4.Text = "Tow Values Product ";
//
// FormApp
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(424, 299);
this.Controls.Add(this.labelElement4);
this.Controls.Add(this.labelElement3);
this.Controls.Add(this.listProductBox);
this.Controls.Add(this.listTwoBoxValues);
this.Controls.Add(this.submitButton);
this.Controls.Add(this.secondTextValue);
this.Controls.Add(this.labelElement2);
this.Controls.Add(this.firstTextValue);
this.Controls.Add(this.labelElement1);
this.Name = "FormApp";
this.Text = "Product Two Values";
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.Label labelElement1;
private System.Windows.Forms.TextBox firstTextValue;
private System.Windows.Forms.TextBox secondTextValue;
private System.Windows.Forms.Label labelElement2;
private System.Windows.Forms.Button submitButton;
private System.Windows.Forms.ListBox listTwoBoxValues;
private System.Windows.Forms.ListBox listProductBox;
private System.Windows.Forms.Label labelElement3;
private System.Windows.Forms.Label labelElement4;
}
}

FormApp.cs

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 ValuesProduct
{
public partial class FormApp : Form
{
public FormApp()
{
InitializeComponent();
}

private void submitButtonClick(object sender, EventArgs e)
{
try
{
if (firstTextValue.Text =="")
{
MessageBox.Show("Enter First Value");
firstTextValue.Focus();
return;
}
if (secondTextValue.Text =="")
{
MessageBox.Show("Enter Second Value");
secondTextValue.Focus();
return;
}
int valueFirstContent = Convert.ToInt32(firstTextValue.Text);
int valueSecondContent = Convert.ToInt32(secondTextValue.Text);
int product=valueFirstContent*valueSecondContent;
AddValuesListBox(valueFirstContent, valueSecondContent);
ProductValuesListBox(product);
}
catch (Exception Ex)
{

MessageBox.Show(Ex.InnerException.ToString());
}

}

private void AddValuesListBox(int valueFirstContent, int valueSecondContent)
{
try
{
listTwoBoxValues.Items.Add(valueFirstContent);
listTwoBoxValues.Items.Add(valueSecondContent);
}
catch (Exception Ex)
{

MessageBox.Show(Ex.InnerException.ToString());
}

}
private void ProductValuesListBox(int product)
{
try
{
listProductBox.Items.Add(product);

}
catch (Exception Ex)
{

MessageBox.Show(Ex.InnerException.ToString());
}

}

private void keyPressFirstTextValue(object sender, KeyPressEventArgs e)
{
// only allow numbers
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) )
{
e.Handled = true;
}

}

private void keyPressSecondTextValue(object sender, KeyPressEventArgs e)
{
// only allow numbers
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
{
e.Handled = true;
}
}
}
}


Related Solutions

IN C++ Write a program that reads in int values from the user until they enter...
IN C++ Write a program that reads in int values from the user until they enter a negative number like -1. Once the user has finished entering numbers, print out the highest value they’ve entered, the lowest value they’ve entered, and the total number of numbers they’ve entered. The negative number they entered should not be taken as one of the values entered.
how to write in java; Write a method int[] coPrime[int num, int[]numbers] { // instructions are...
how to write in java; Write a method int[] coPrime[int num, int[]numbers] { // instructions are that it returns an array of all the elements of the int[] array numbers which are coprime with x } Note that the array that is returned may be an empty array--you will have to count how many times gcf(x, numbers[i]) == 1. ASSUME numbers is not null and not empty.
Write a method which is passed A[], which is an array of int, and an int...
Write a method which is passed A[], which is an array of int, and an int passingScore. The method returns the number of items in A[] which are greater than or equal to passingScore. Write a method which is passed an array of int A[]. The method returns true if A[] is the same backwards and forwards. Write a method same( ), which is passed two arrays of int. The method returns true if the two arrays contain exactly the...
Write application in C# that enables a user to: Use Methods for user input and calculations...
Write application in C# that enables a user to: Use Methods for user input and calculations input the grade and number of credit hours for any number of courses. Calculate the GPA on a 4.0 scale using those values. Grade point average (GPA) is calculated by dividing the total amount of grade points earned, sometimes referred to as quality points, by the total number of credit hours attempted. For each hour, an A receives 4 grade or quality points, a...
Design a class named ArraySort and it contains the following method: Public int search(int target): if...
Design a class named ArraySort and it contains the following method: Public int search(int target): if the target is found in the array, return the number of its showing up. If the target is not found in the array, return -1. If the array is empty, return -1; Public int maximum():Return the maximum number in the array if the array is nonempty, otherwise return -1; Public int minimum(): Return the minimum number in the array if the array is nonempty,...
Write a program that asks the user to type in two integer values. Test these two...
Write a program that asks the user to type in two integer values. Test these two numbers to determine whether the first is evenly divisible by the second and then display the appropriate message to the terminal. Objective C
(java)Write a recursive method public static int sumForEachOther(Int n) that takes a positive Int as an...
(java)Write a recursive method public static int sumForEachOther(Int n) that takes a positive Int as an argument and returns the sum for every other Int from n down to 1. For example, sumForEachOther(8) should return 20, since 8+6+4+ 2=20.And the call sumForEachOther(9) should return 25 since 9+7+5 + 3+1-=25. Your method must use recursion.
This problem requires python(Project: Evaluate Word Problems) Write a script that enables the user to enter...
This problem requires python(Project: Evaluate Word Problems) Write a script that enables the user to enter mathematical word problems like "two times three" and " seven minus five", then use string processing to break apart the string into the numbers and the operation and return the result. So “two times three” would return 6 and “seven minus five would return 2. To keep things simple, assume the user enters only the words for the numbers 0 through 9 and only...
Write a C program that asks the user to enter double values (the values can be...
Write a C program that asks the user to enter double values (the values can be positive, zero, or negative). After entering the first double value, the program asks "Would you like to enter another value?", and if the user enters Y or y, the program continues to get additional values and stores these values into a double array (for up to 100 values — use a symbolic #define constant to specify the 100 size limit). The program will need...
Write an application that allows a user to enter the names and birthdates of up to...
Write an application that allows a user to enter the names and birthdates of up to 10 friends. Continue to prompt the user for names and birthdates until the user enters the sentinel value ZZZ for a name or has entered 10 names, whichever comes first. When the user is finished entering names, produce a count of how many names were entered, and then display the names. In a loop, continuously ask the user to type one of the names...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT