VB.NET Salary Calculator: Creating Employee Object & Determining Weekly Salary, Exams of Computer Science

The creation of an employee object in visual basic.net, using an arraylist to store the objects and determine weekly salaries based on regular and overtime hours. Instructions for setting up the form, creating the employee class, and implementing the weeklysalary, regulartime, and overtime functions.

Typology: Exams

Pre 2010

Uploaded on 10/12/2009

koofers-user-cw2-1
koofers-user-cw2-1 🇺🇸

5

(1)

10 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
0
Exam 2 Question'2 (Estimated Time: 65 min)
CGS 2421 Visual Basic.NET
Summer ZObg ,
, Project Name:.Salary Calculator
- i -'
lntroduction:
As a pay roll manager, you determine that ,you need a quick way, outside of -excel, to
determine yourt'einployees' expected weekly pay given'their pay level and the number of
hours they work in a week.
How it works:
Each employee is represented by'ai"Employee object. The program you will build uses an
arraylist (not array) to contain Employee objects to which the attributes df first name,
last name and pay level are,ascri6ed. This object class will have a PI/BLIC function that
returns the employee's Weekly Salary by detefmining how many hours of a given week
are Regular Time (in our case, hours 0 thru 40) and Oier Time (any work beyond 40
hours). . * '
: -- .^l
Public Class Employee
Pubiic nameFirsi, namelast; leveI As String
,r
Public Sub New.:. 'ci:reai,e:;1ew..""t,1,r." c7r1ci.ts:s-(Tls ilct:.ixiei:c:r'.g
Pubtic Function WeeklySalary (ByVal, hours. 'hs Double)
Private Function RegufarTime(ByVat regularhours As Double)
Private Function Overtime(ByVa1 overtimehours As Double)
EndClass,,*r,r
r r ',
The Emplo,yee objects are storedln an arraylist and are called upon to update a listview of '
the employee names. Output oT hours worked is in the fo'rm of a messagebox'.
Pay rates for given pay levels are as follows:.
Level ular Overtime
Elecutive S ss.2s s 82.87s
Mid-Level Manager 's,- 37.1.5 S ss.72s
Neril Hire s _ 2250 $ gt.zso
HINT:'Notice that overtime'is EXACTLY 1.5 times regular tim-e.
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download VB.NET Salary Calculator: Creating Employee Object & Determining Weekly Salary and more Exams Computer Science in PDF only on Docsity!

0

Exam 2 Question'2 (Estimated^ Time:^65 min)

CGS 2421 Visual Basic.NET Summer ZObg ,

, Project Name:.Salary Calculator

  • i -'

lntroduction:

As a pay roll manager, you determine that ,you need a^ quick way,^ outside^ of^

-excel, to

determine yourt'einployees' expected^ weekly^ pay^ given'their pay^ level^ and the number^ of

hours they work in^ a^ week.

How it works:

Each employee is represented by'ai"Employee object.^ The program^ you^ will^ build^ uses^ an arraylist (not^ array) to contain Employee^ objects^ to^ which^ the^ attributes^ df^ first^ name, last name and pay^ level^ are,ascri6ed.^ This^ object^ class^ will^ have^ a^ PI/BLIC^ function^ that

returns the employee's Weekly Salary by^ detefmining how many hours^ of^ a^ given^ week

are Regular Time (in^ our^ case,^ hours^0 thru^ 40)^ and^ Oier^ Time (any work^ beyond 40 hours)..^

  • (^) '

: -- .^l

Public Class Employee

Pubiic nameFirsi, namelast; leveI As String,r

Public Sub New.:. 'ci:reai,e:;1ew..""t,1,r."^ c7r1ci.ts:s-(Tls ilct:.ixiei:c:r'.g

Pubtic Function WeeklySalary (ByVal,^ hours.^ 'hs (^) Double)

Private Function RegufarTime(ByVat regularhours As^ Double)

Private Function Overtime(ByVa1 overtimehours As^ Double) EndClass,,*r,r

r (^) r ',

The Emplo,yee objects are storedln an arraylist and^ are^ called^ upon to^ update^ a^ listview^ of^ '

the employee names. Output^ oT^ hours worked is^ in^ the^ fo'rm^ of^ a^ messagebox'. Pay rates for given pay^ levels are as follows:. Level ular^ Overtime Elecutive (^) S ss.2s s 82.87s Mid-Level Manager 's,-^ 37.1.5^ S ss.72s Neril Hire (^) s _ 2250 $ gt.zso HINT:'Notice that overtime'is EXACTLY 1.5 times regular tim-e.

f,he GUI:

' ;^

-t' ' 'The ; GUI has I groupbbx,4 labels, 3 textbox6s, 2 buttons,^1 combobox,^ and^ one^ listview.

. ,You,'must^ add i-h".oln.nns to the listview in desi$n rhode, and'into the combbbox you

must add the default^ text^ as^ well^ at^ the^ following"selectable^ itehs:^ Executive,^ Mid-Level

oManager, and New Hire, in that orddr. See walkthrough to check for correctness.

lset the listview-so that ENTIRE ROWS are selectable, not.-- just^ indivihud cells.

lo.q.rA. STRUCTURE: n^

This program.will uie I^ arraylist^ (not^ array)^ as^ its^ data structure.^ This anaylist^ will store^ :

' rreferenc is to'Employee objects. The^ anaylist^ will^ be^ called^ on^ to^ fipdate^ the^ listview.^ See

""Code Given. r{.

r'w r^ '':^ -;^ f

ADD Button:

!E : i

rUser (^) will have put (^) in a first and last"hame asiwell haie selected apay ldvel'(there will be 'lNO (^) ERROR CHECKING for this)."This info will be used to create a new "Employee" object, which will be added^ fo^ the"employdelist arraylist^ (see^ code giv'en).^ The^ listview must then be updated for'the^ new addition.^ Both textboxes^ will^ be^ cleared, the combobox will be reset and tbxFirstName_will be foc-used upon.

i

CODE GIVENi

Publii CIass Forml

Drirra+.a!!rwsve amnlgyee|,iSt Asv^rrF New ArrayliSt

Private Sub btnAdd-C1ick... Dim newEmployee^ As^ Employee^ : Dim fName, 1Name, leriel^ As^ String l l' i fName^ =^ tbxFirstName.Text. fuame (^) = tbxlastName.Text^ *"

  • 1eve1^ =^ cmbl,evel.Text newEmployee (^) = New Employee(fName, INamij,^ level)

'::. !;nd Sul)

Private Sub^ btnReport-Click... Dim enteredHours As^ Double^ i

1l_^ I^ Dim^ currentEmployee^ As^ Employee^ i

Dim employeeSelecLed As'Integer

  • enteredHours =- tbxHours.Text

If (lwuNames.Selectedlndices.Count > 0)^ Then

employeeSelected = fvwi.lames. Selectedlndices (0^ )

currentEmployee (^) = ...

t

. End^ ri

End Sub,'

r Privat.e^ "Sub^ UbdateListview^ (^ ) ':.'ie..i::s^ tt:'Lcl^ :.iS><1;tt.r:si^ i-ldi.^ v-j^ en'

Private Sub^ lvwNa*"s-feyOott...^ ''DE:.E'TE^ i'lt"2"' :;tin.r-,'icilt-r^ <>i;cd^ a[tovt:

t"

r Public Cfass Employee

' 4^ Public nameFirst, namelast, 1evel As Scring

Ir

Pubf ic Sub^ New...^ 'creates^ nelr'^ er?lrlo5'ee^ artd^ ass:gi:s^ pa-rarilerez's

Public Function WeeklySalarV,(BVVal hours As^ Double)

'tleek.71, Sal-art, ccilli)Li Les ToTAL weekii: saiarT', z-egariiess o-f i:ou:.s,

bv tts-rig {-ite rNIVA'IL. I'UNC"}"'iOff.5 iteqr.rlarl'ine and^ (tvez''i."me.^ ii-^ i-;iles

the number^ of^ hours^ wo:'ked^ and^ assiglTs^ a^ max^ of^ 4A^ hours^ to^ be

conputt-:ci by Rt-tgr,.;iarTint-.'. arid^ t-hcn^ iakr:^c^ any^ ov.:rdiJC^ ovL:r^ tiC^ ii<>t;r's

"anti c:c;rnput. es: f.h€i csver"t. irne b.i. ci.ti i inq Over. ?:rne.

Private Function RegularTime (ByVal regularhours^ As^ jDouble)

'P,egr1la1gir.e conpr:ies^ O:{LY^ :',!guiau^ t^ j^ me^ i-hat i-s iriil:rc1ed ir:^ i.he

viee::iy :;.r. 1-at:'i/ (:r.<1;r^ oi 40 :rt>i.l: s; ).. it. clei-e::lj-:res: wl.ai- t-ile pay'r'<l!.e^ i::

frtr uhe.-,r--: nirren rrarz lF,'e-l ::tr-.1 lennnrr-pqr-Jr.rFs!!! f.)-al^ rFrlt:l;r*-ii.rrrv!r'q+!+! naV.

r Privat.e Function OverLime(ByVal overtimehours As Double)^ |

'O'.ze::{-"irne coJniauces ulv-i}" o/el:linig tl:at is iricfuCed in'che weei:i-,''

:;a)ary. Siini!ar i.r:^ R<:gu^ )'ar'l'inx:.-, il:^ cit:ct::'rniric*c^ wi;at.^ tlit'^ Fay2-urr,, ii;

.[<;r i-t]e^ cl:r',;cri^ par'^ 1'ever^ o..ttt<.i (.'(jln])i.ll.eir^ (-)/(.)al-^ jr'r€l^ paY.^ kec.l^ I^ )^ i-hr:r

ov.-r?'i: jir() I)e)- i.t" ctx.rc:f ,l- 'i^ .5 r:inr:;; i't-:gu'l art.izi.c: i);11'. I'olr r'.-..r') .sdva, d

fev,, n;:::uf^ es rl, actinq cn tlt)s^ icnctwJedEe.

End Class

PROGRAM CHECKLIST:

o Be sure to adherdto every requirement for the Add button (under^ Form Controls).

o There is no error checking for nonsense inputs or an invalid selected index in the listview.

o Pay careful attention to the^ messagebox^ generated^ by^ the^ report button^ (see walkthrough). Be sure that the formats match up, and notice that the dollar output is formatted. Don't worry^ about using^ floor^ or^ ceiling^ on this^ value.

o Your program MUST use the object class given; WeeklySalary MUST be public, and calls on RegularTime and OverTime, which MUST be private.

o Be sure to set the listview so that when clicked, an entire row is selected and not just^ an

individual cell (see walkthrough). It is okay for the "selection" appearance to go away

when you^ click outside of the listview. The selected index remains.

PROGRAM WALKTHROUGH: Your program^ should behave exactly as follows!

i":F,'fttlvl'l:yb:9'_ a-

,| tflpl0)'eelntormatrun

t? r ,i First^ Hame,^ .i--^

" j\

. Last^ lJame. '_ Level: (^) Select Pal,Level

'Add (^) Employee

l'dage TCeekly Hours :

| ...^ Tg.P*?T&rlYeeh'ssalarrr' -.ll

**16@,rt,i.,qt$f&-iqs

L_* (^) *

Step 1: Form loads.

Employee|nformation (^) |,--,,I LEC! name ilI$ f{Ame t (^) Firut tl"** (^) : (^) i-- | o'e,i"n conan

: (^) Laet Name:^ I^ Leno^ Jay

Select Pd,r Gvd

i

.. tttage

lVeek[ Haurs : Repsrt'Ihrs WEek's Salary t, t I

Step 4: User repeats steps 2-3 for second employee, choosing "Executive" as the

employee's pay level. Again, focus returns to First Name textbox.

I uut^ t',tur"^ Frrst^ Name

I I I LenC' Jd)'

Step 5: User has typed "60"^ into the hours field, and selects the first employee.

Step 6: User clicks Report, and receiveb^ the^ above^ statement.^ It^ is^ normal for^ the'selected

ListView item to no longer appear selected.

Emdoyee lnfaniietisn^ i | t"ut""'''^ tlu"^ Rrgt^ FJame Fir$ Name.:. I O"Bilan fsnan Last l,iame : Level :

I .tI , I I I I' !, I i

r'+"Qrr"r ,.* ' : d.:f#'.iq. .t

Select Pay Level^ v

Fdd Emplsyge

lVage l$'eekl'l (^) Hguru : (^) ,€

Step 7: User selects the other employee;^ and^ is^ about to^ click^ Report.

-{*f

*+

f; Emplsree lnformatian (^) : (^) FirS Name

Laet Name. Level: (^) Select pay (^) Level

tAtege

Weekly Hours : '6il

Step 10: User hits the ' DELETE key^ and^ the^ selected^ employee^ has^ disappeared^ (from both the^ arraylist and, consequently,^ the^ listview).

,

'l I I 1 1