Docsity

Compute Salary Application - Version 2 - Prof. Nancy Mccracken, Lab Reports of Information Technology

Toggle sidebar
bg1
IST 256
Lab Week 3, Part 1 - September 10, 2008
1. Compute Salary – extending the compute salary program
For this application, you should open Visual Studio and create a new project
named something like ComputeSalary. This new project should be in the same lab
projects folder as usual.
In the initial form, change the text property of the form for the new
ComputeSalary project.
Version 1 – In-class:
In class, an application was developed for a simpler version of the ComputeSalary
program. The application description was:
Write an application that allows the user to type in the number of hours that they
worked in a week. Then they can click on a button to compute the salary for that
week. The salary is computed as follows: if the number of hours per week is less
than or equal to 40, then the pay rate is $10 per hour and otherwise it is $15 per hour.
Display the salary and allow the user to close the application.
In the form design, there was a label with instructions to the user: “Type number of hours
worked” next to a textbox. There was an (initially invisible) label to display the salary.
There were two buttons, one with “Compute Salary” and the other with “Close”.
In the program, there were
- two variables: Hours and Salary, both of type single to allow for decimal numbers.
- code for the Compute Salary button was to get the hours from the textbox. If the hours
were <= 40, then salary was computed as hours * $10 and otherwise the salary was
computed as hours * $15.
- code for the Close button ends the program.
Here is the program:
‘ The ComputeSalary program takes hours worked and computes salary
‘ Programmer: Nancy McCracken
Public Class Form1
' User will type in hours, salary will be computed
Dim Hours, Salary As Single
' Compute the Salary from the number of hours worked
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
' get the hours from the textbox
Hours = CSng(TextBox1.Text)
' if hours <= 40, pay rate is $10 otherwise rate is $15
If Hours <= 40 Then
Salary = Hours * 10.0
Else
Salary = Hours * 15.0
pf2

Partial preview of the text

Download Compute Salary Application - Version 2 - Prof. Nancy Mccracken and more Lab Reports Information Technology in PDF only on Docsity!

IST 256

Lab Week 3, Part 1 - September 10, 2008

1. Compute Salary – extending the compute salary program

For this application, you should open Visual Studio and create a new project

named something like ComputeSalary. This new project should be in the same lab

projects folder as usual.

In the initial form , change the text property of the form for the new

ComputeSalary project.

Version 1 – In-class:

In class, an application was developed for a simpler version of the ComputeSalary

program. The application description was:

Write an application that allows the user to type in the number of hours that they

worked in a week. Then they can click on a button to compute the salary for that

week. The salary is computed as follows: if the number of hours per week is less

than or equal to 40, then the pay rate is $10 per hour and otherwise it is $15 per hour.

Display the salary and allow the user to close the application.

In the form design, there was a label with instructions to the user: “Type number of hours

worked” next to a textbox. There was an (initially invisible) label to display the salary.

There were two buttons, one with “Compute Salary” and the other with “Close”.

In the program, there were

- two variables: Hours and Salary, both of type single to allow for decimal numbers.

- code for the Compute Salary button was to get the hours from the textbox. If the hours

were <= 40, then salary was computed as hours * $10 and otherwise the salary was

computed as hours * $15.

- code for the Close button ends the program.

Here is the program:

‘ The ComputeSalary program takes hours worked and computes salary

‘ Programmer: Nancy McCracken

Public Class Form ' User will type in hours, salary will be computed Dim Hours, Salary As Single

' Compute the Salary from the number of hours worked Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' get the hours from the textbox Hours = CSng(TextBox1.Text)

' if hours <= 40, pay rate is $10 otherwise rate is $ If Hours <= 40 Then Salary = Hours * 10. Else Salary = Hours * 15.

End If

' make label text with the salary and display Label2.Text = "Salary = " & Format(Salary, "currency") Label2.Visible = True ' make other objects not visible Label1.Visible = False TextBox1.Visible = False End Sub

' Close the form Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click End End Sub End Class

Version 2: Lab

For lab today, you are to design another Compute Salary application that is extended from

this one. This application description is as follows:

Write an application that allows the user to type in the number of hours that they

worked in a week. Then they should type in a 0 if they worked the day shift or a 1 if

they worked the night shift. Then they can click on a button to compute the salary for

that week. The salary is computed as follows:

if the number of hours per week is <= 40, then the pay rate is $

and otherwise the pay rate is $

if they work the night shift, then they get a bonus of $20 added to their salary

Display the salary and allow the user to close the application.

First decide on what additional objects you need to put on the form. One more label and

one more textbox?

Next you will need an additional variable to hold their day/night shift status. This

variable can be declared as an integer, possibly called status.

Add code to the Compute Salary button to use both the hours and the status to compute

the salary as described in the application description.

Test your program with different values and show the results here. Is it working?

Test Runs Hours Status Salary

Print the Form1.vb page of your program. Staple together the Monday’s lab pages,

today’s lab pages, and the program and hand it all in.