namespace ST23
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
const decimal BASE_FUND = 15000m; (0.5)(decimal const declared as a field else 0 if not a field)
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
private void button3_Click(object sender, EventArgs e)
{
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
btnProcess.Visible = true; (0.5)( (checkchanged of checkbox, visible true)
}
private void Form1_Load(object sender, EventArgs e)
{
this.BackColor = Color.Beige;
btnProcess.Visible = false; (0.5 for back colour, 0.5 for button visible)
private void btnProcess_Click(object sender, EventArgs e)
{
string name = txtNAme.Text;
string employmentType = "";
int yearsFunded = 0;
if (int.TryParse(txtAge.Text, out int age) && age >= 18 && age <= 36)
(1 mark for for using int.tryparse in an if clause and correct arguments of tryparse)
((0.5) for input invalidation for ages between 18 and 36)
{
decimal fund = 0m;
if (rdoYes.Checked)
{
fund = BASE_FUND + 25000;
(1 mark for .checked property for both radio buttons , else 0)
(1 mark adding correct amount to base fund – half for rdoYes and half for rdoNo )
}
else if (rdoNo.Checked)
{
fund = BASE_FUND + 40000;
}
else
{
MessageBox.Show("Please indicate whether you have received funding before or not");
(0.5)( (1 mark for the else, otherwise people get away with not selecting radio
button )
}
if (lstChoice.SelectedIndex !=-1)
(1 mark for using selected index property and it not being less than 0)
{
employmentType = lstChoice.SelectedItem.ToString();
(selected item property correctly used with tostring method and result saved in variable)
switch (employmentType)
(1 mark for keyword with result that is selected from Choicelistbox, as text expression)
{
case "Employed - Full time": yearsFunded = 3; break;
case "Employed - Part time": yearsFunded = 3; break;
case "Unemployed": yearsFunded = 3; break;
case "Self-employed": yearsFunded = 4; break;
case "Entrepreneur": yearsFunded = 5; break;
case "Tenderpreneur": yearsFunded = 3; break;
default: MessageBox.Show("Please select the relvant employment type");break;
(2 marks for all cases 100% correct, 1 mark if atleast one is not incorrect, 0.5 if 2 or
less are correct)
}
Random jare = new Random();
(1 mark correctly creating random object )
int count = 1; (1 mark for create and initialize counter variable outside loop)
decimal totalFund = 0m;
lstOutput.Items.Add("Funding application receipt for " + name + ":");
lstOutput.Items.Add("");
while (count <= yearsFunded)
(while keyword and test correct condition)
{
int receiptNum = jare.Next(100000, 1000000);
(save random result in int variable, call next method, generate atleast 100 possible 6digit
results ) = All or nothing
lstOutput.Items.Add("Funding for year " + count + " will be " + fund.ToString("c") + " with payout reference: " +
receiptNum);
(Items.add method in the loop)
(format to string with “c” argument)
lstOutput.Items.Add("");
count++; (increment count variable)
totalFund += fund; (update the total fund each iteration in the loop)
lstOutput.Items.Add("If approved; the total funded amount, will be " + totalFund.ToString("c"));
(display final totalfund once after all iterations)
}
else
{
MessageBox.Show("Please select the relevant employment type");
}
}
else
{
MessageBox.Show("Your age disqualifies you, you muste be between 18 and 36");
(0.5) ( ensure user knows what they did wrong)
private void pictureBox1_Click(object sender, EventArgs e)
(1) (picture correctly imported to picturebox image property)
{
this.Close();
(0.5) (close method behind picture)
private void btnNewApp_Click(object sender, EventArgs e)
{
txtAge.Clear();
txtNAme.Text = "";
rdoNo.Checked = false;
rdoYes.Checked = false;
lstOutput.Items.Clear();
txtNAme.Focus();
checkBox1.Checked = false;
lstChoice.SelectedIndex = -1;
(1 mark if 100% correct)
}
}
}
(0.5) access key on the S of submit button.
(0.5) HCI compliant- GUI looks exactly same as output example.
(0.5) correct output displayed 100% as output example.
PART 2
Using System.IO; (0.5) ( 0.5 mark if 100 % correct)
private void button1_Click(object sender, EventArgs e)
{
StreamWriter skryf; (0.5 for object and 0.5 for closing file (below)
if (saveFileDialog1.ShowDialog() == DialogResult.OK) ( 1 mark if 100 % correct)
skryf = File.AppendText(saveFileDialog1.FileName); ( 1 mark if 100 % correct)
for (int i = 0; i < lstOutput.Items.Count; i++)
{
skryf.WriteLine(lstOutput.Items[i]);
( appropriate and effective method used to write items from listbox to a file)
}
skryf.Close();
}
}
private void button2_Click(object sender, EventArgs e)
{
listBox1.Items.Add("The content below has been read from a file");
StreamReader lees; ( 1 mark if 100 % correct)
if (openFileDialog1.ShowDialog() == DialogResult.OK) ( 1 mark if 100 % correct)
lees = File.OpenText(openFileDialog1.FileName); ( 1 mark if 100 % correct)
while (lees.EndOfStream == false) ( 1 mark if 100 % correct)
{
listBox1.Items.Add(lees.ReadLine()); ( 1 mark if 100 % correct)
}
lees.Close();
}
(File successfully written to a location and located with openfiledialog )