0% found this document useful (0 votes)
48 views

Lab Exercises (Not Graded)

The document outlines 4 lab exercises for students: 1. An application that reads an integer and determines if it is odd or even using the remainder operator. 2. A class called Invoice for a hardware store with properties for part number, description, quantity, and price per item along with a method to calculate the total invoice amount. 3. A class called Employee with properties for first name, last name, and monthly salary along with demonstrating salary calculations for two employees. 4. A class called Date with automatic properties for month, day, and year along with a method to display the date in MM/DD/YYYY format.

Uploaded by

Rishad Shariq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Lab Exercises (Not Graded)

The document outlines 4 lab exercises for students: 1. An application that reads an integer and determines if it is odd or even using the remainder operator. 2. A class called Invoice for a hardware store with properties for part number, description, quantity, and price per item along with a method to calculate the total invoice amount. 3. A class called Employee with properties for first name, last name, and monthly salary along with demonstrating salary calculations for two employees. 4. A class called Date with automatic properties for month, day, and year along with a method to display the date in MM/DD/YYYY format.

Uploaded by

Rishad Shariq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Lab Exercises (Not Graded)

1. (Odd or Even) Write an application that reads an integer, then determines and displays

whether it’s odd or even. [Hint: Use the remainder operator. An even number is a

multiple of 2. Any multiple of 2 leaves a remainder of 0 when divided by 2.]

2. (Invoice Class) Create a class called Invoice that a hardware store might use to represent

an invoice for an item sold at the store. An Invoice should include four pieces of

information as either instance variables or automatic properties—a part number (type

string), a part description (type string), a quantity of the item being purchased (type int)

and a price per item (decimal). Your class should have a constructor that initializes the

four values. Provide a property with a get and set accessor for any instance variables. For

the Quantity and PricePerItem properties, if the value passed to the set accessor is

negative, the value of the instance variable should be left unchanged. Also, provide a

method named GetInvoiceAmount that calculates the invoice amount (i.e., multiplies the

quantity by the price per item), then returns the amount as a decimal value. Write a test

application named InvoiceTest that demonstrates class Invoice’s capabilities.

3. Create a class called Employee that includes three pieces of information as either instance

variables or automatic properties—a first name (type string), a last name (type string) and

a monthly salary (decimal). Your class should have a constructor that initializes the three

values. Provide a property with a get and set accessor for any instance variables. If the

monthly salary is negative, the set accessor should leave the instance variable unchanged.

Write a test application named EmployeeTest that demonstrates class Employee’s


capabilities. Create two Employee objects and display each object’s yearly salary. Then

give each Employee a 10% raise and display each Employee’s yearly salary again.

4. Create a class called Date that includes three pieces of information as automatic

properties—a month (type int), a day (type int) and a year (type int). Your class should

have a constructor that initializes the three automatic properties and assumes that the

values provided are correct. Provide a method DisplayDate that displays the month, day

and year separated by forward slashes (/). Write a test application named DateTest that

demonstrates class Date’s capabilities.

You might also like