C# APPLICATION REQUIREMENTS: Requirement 1: The application displays a new multi
ID: 3902083 • Letter: C
Question
C#
APPLICATION REQUIREMENTS:
Requirement 1: The application displays a new multiplication question every time the "New" button is clicked.
Requirement 2: 10 message boxes are displays indicating the remaining time in seconds.
Requirement 3: The "Time" displayed by the application decreases by 1 until it reaches 0 sec (before the user can enter an answer).
Requirement 4: The "Score" displayed by the application increases by 20 points for every correct answer.
INSTRUCTIONS:
2. In the NewButton_click method, create the following:
· A random variable
· Two integer variables: var1 and var2
3. Set the values of variables var1 and var2 to random numbers smaller than 10.
4. Change the text of the PromptLabel to prompt the user to enter the product of var1 and var2.
5. Set the product variable to the product of var1 and var2.
6. Create a for loop to:
· Display 10 message boxes, each with a countdown from 10 to 0.
· Change the text of the TimeLabel to show the correct number (countdown from 10 to 0).
5. In the SubmitButton_Click method, add code to increase the score by 20 points for every correct answer.
7. Run your program to make sure that it works as expected.
Explanation / Answer
As per your requirement i have written code which fulfill all your requirements please follow it step by step.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace Windowsformapplication
{
public partial class FormClass1 : Form
{
int scoreValue,productValue;
public FormClass1()
{
InitializeComponent();
// Here we will intilize the value
scoreValue = 0;
}
private void button1ClickedMethod(object senderObject, EventArgs eventObject)
{
}
private void NewButton_click(object senderObject, MouseEventArgs eventObject)
{
// Here we created object for random method
Random randomObject = new Random();
int r, var1, var2, productValue;
// Assign randomly generated values for var1
var1 = randomObject.Next(1, 9);
// Assign randomly generated values for var2
var2 = randomObject.Next(1, 9);
PromptLabel.Text = "Enter Product of " + var1 + "and" + var2;
// Calculate the result
productValue = var1 * var2;
for (r = 10; r >= 1; r--)
{
MessageBox.Show(r.ToString ());
TimeLabel.Text = r.ToString ();
System.Threading.Thread.Sleep(1000);
}
}
private void SubmitButton_Click(object senderObject, EventArgs eventObject)
{
// Checks the condition whether it satifies or not
if(Convert.ToInt32 (textBox1.Text) == productValue)
scoreValue = scoreValue + 20;
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.