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.
Write a java code that ask users to pick two of the job categories and enter...
Write a java code that ask users to pick two of the job categories and enter two working areas from each category. The users must enter the start and end time for each of the two selection and calculate the hours for each category and the total hours for all the categories. If the users total hours is more that 10 hours, they are awesome, if not, they are lazy. Shor and simple code using while or for loops. Thanks...
Design an application with a single class and two static methods: method main and method isLeap....
Design an application with a single class and two static methods: method main and method isLeap. Static method isLeap accepts year as integer and returns boolean value true or false depending whether year is leap or not. public static boolean isLeap ( int year ) The year is leap year if it is divisible by 4, but not divisible by 100 except if it is divisible by 400. Examples 2007 is not a leap year 2008 is leap year 1700...
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 method with the following header: public static char calculateLetterGrade(int grade, int totalMarks) This method...
Write a method with the following header: public static char calculateLetterGrade(int grade, int totalMarks) This method calculates grade/totalMarks and returns a letter grade based on the following scale: 0-50 = F 51-60 = D 61-70 = C 71-80 = B 81-100 = A
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
Write a static method remove(int v, int[] in) that will return a new array of the...
Write a static method remove(int v, int[] in) that will return a new array of the integers in the given array, but with the value v removed. For example, if v is 3 and in contains 0, 1, 3, 2, 3, 0, 3, and 1, the method will return an array containing 0, 1, 2, 0, and 1. Hint: You can follow two steps to solve this problem: Create an array in the method, let say you called it result....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT