OBJECT ORIENTED PROGRAMMING, LABORATORY EXERCISES
EXERCISE NO. 2
OBJECTIVE:
Be able to apply concepts on Properties and Behavior
DIRECTIONS:
Create a new project (Windows Application). Save the project as pe#_act2,
example: pe12_act2.
1. Resize the form using the Properties Windows (View - Properties Window)
as: 346 (Width), 188 (Height).
Forms (besan)*
reat te
efetaetinyor Fake
2. Change the Text Property of the form as Working with Properties and
Behavior.
3. Insert a button by opening the Toolbox Window (View - Toolbox).
4. To insert a button, either double click it or select the button and drag it in
the form.
5. Position the button at the center of the form and set the Text Property as
Press Me.
MR. EDMUND D. EVANGELISTA, University of Saint Louis Page 1OBJECT ORIENTED PROGRAMMING, LABORATORY EXERCISES
—
re
Se
anon
6. Double click the button and type the given codes below:
//Declares a date variable and stores the current date & time
DateTime otm = DateTime.Now;
//Stores into a String variable if the current time is AM or PM
String strAMPM = otm.ToString("tt");
//A simple use of if and else statement
if (strAMPM == "AM")
MessageBox.Show("Good morning, I am Jack Mawatan.");
else
MessageBox.Show("Good afternoon, I am Jack Mawatan");
7. Run the program.
18 Working with Properties and Behaviors os
Press Me Good afternoon, [am Jack Mawatan
MR. EDMUND D. EVANGELISTA, University of Saint Louis Page 2OBJECT ORIENTED PROGRAMMING, LABORATORY EXERCISES
EXERCISE NO. 3
OBJECTIVES:
Be able to apply concepts on Properties, Behavior and Nested If
PROBLEM:
Write an application that can convert a certain amount of money from one
type of currency to another.
DIRECTIONS:
Create a new project (Windows Application). Save the project as pe#_act3,
example: pe12_act3.
1.
Set the size of the form as 294, 187 and the text as Currency Converter.
Set also the BackColor property as Info.
. Insert a label in the form with a text Money Changer. Position it at the
center of the form.
. Insert another label below with a text Amount:. Insert a textbox beside the
label. Set the Name property as txtAmount.
Insert a label below with a text Currency:. Insert a textbox beside the label.
Set the Name property as txtCurrency.
Insert another label below with a text Converted:. Insert a textbox beside
the label. Set the Name property as txtConverted.
Note: This program will assume the following rate of exchange per Philippine
Peso. For other types of currencies not mentioned, the program will just
display an error message.
* D_ Dollar 44.50
" Y Yen 0.58
= R Riyal 18.43
"=P Pound 115.65
6. Insert a button with a text Compute. Double click the button and insert the
given code below
MR. EDMUND D. EVANGELISTA, University of Saint Louis Page 1OBJECT ORIENTED PROGRAMMING, LABORATORY EXERCISES
//Declares a variable
double amount, converted = 0, exchange = 0;
char currency;
//Stores the value of each textbox into a variable
amount = Convert.ToDouble(txtAmount.Text);
currency = Convert.ToChar(txtCurrency.Text);
//Uses nested i
if (currency == 'D' || currency == 'd")
exchange = 44.50;
else if (currency == 'Y' || currency == 'y')
exchange = 0.58;
else if (currency == 'R' || currency == 'r')
exchange = 18.43
else if (currency == 'P' || currency == 'p')
exchange = 115.65;
else
MessageBox.Show("Sorry, not available!");
converted = amount * exchange;
txtConverted. Text = "P" + Convert.ToString(converted);
7. Insert another button with a text Cancel. Double click the button and insert
the given codes below:
txtAmount.Clear();
txtConverted.Clear();
txtCurrency.Clear();
8. Run your application
Te eee
Money Changer
Amount: [300
Money Changer
oat (30
Cunenes. [Ol Baenex [D
Conve. |PISES0
MR. EDMUND D. EVANGELISTA, University of Saint Louis Page 2