First Program Exercises

Structure of OOP:
Object.Property: A set of properties that describe an object.
For example, color, size, and text content of a car: Car.Color, Door.Size, and Message.Text.
Object.Method: A set of behaviors (actions) for the object.
For example, driving a car: Transmission.Engage, Door.Open, and Message.Show.
Encapsulation: Objects come with a lot of pre-written descriptions and functions that users don't have to know in detail. Users can modify the information or behaviors of the object without knowing the specifics of how it is constructed.
Ex: Car.Color = Red
Ex: EngineTempWarning.Text = "It's Realy Hot, so Cool It Donw Now!"
Ex: EngineTempWarning.Show
Here, a programmer does not have to specify in detail, for example, how the Color property takes in the text value of Red since Visual Basic understand what it supposed to do with the information. It's like you saying the word "Red" to an English speaker, and listener knows what it is because the listener is programmed with the concept of the color red.
Inheritance:
Class 1 / Class 2
Food
Fruit
Apple / Machine
Computer
Apple
The Food class has properties that are related to food while the Machine class has properties that are related to machine. Because the Apple subclass under the Food class belongs to the Food class, the Apple subclass has access to all properties that the Food class has. The basic idea is that since Apple is a kind of food, so it should have properties of Food. But the Apple subclass of the the Machine class does not have access to the properties of the Food class since the Apple is a computer and not a fruit.
Polymorphism:
Actions or behaviors that share the same essence would have a common name even though they belong to different objects. In other words, Methods with same names are used for different objects if what they do is essentially the same. For example, opening (method) a computer application (object) is different from opening a door in terms of detail steps. However, the name of the method for both objects is open since the idea is the same. (ComputerApplicatoin.Open and Door1.Open)

Part 1

Follow and complete the step-by-step instruction of Project 1. Save the files in the Project 1 folder on the VB disk.

Part 2

Create the "Hello, World!" program as shown below.

Here are detail steps creating the program:

  1. Open a new Project.
  2. Change the form name in the Solution Explorer to frmHelloWorld. Notice that there is no blank space between the work Hello and World.
  3. Click on the form object.
  4. Change the (name) property in the Properties window to frmHelloWorld.
  5. Scroll down the Properties window to the Text property, and type in My First Program.
  6. Click on the Button tool in the Toolbox window.
  7. Draw a button on the firm.
  8. Click on the button (Button1) to select it. In the Properties window, change the Name property to btnClick and the Text property to "lick Here".
  9. Select the Text tool from the Toolbox window. Then draw a box in the form.
  10. Select the text box object in the form to select it. Change the Name property to txtMessage. And change the font size property to be 20. The font size is under the font property.
  11. On the form, double-click on the button object. That action will trigger the codes window to open.
  12. Type: txtMessage.Text = "Hello, World!" after Private Sub btnClick (...)
  13. Save all by clicking on the icon. Do not use the options under the File menu.
  14. Press F5 to run.
  15. On the Microsoft Development Environment window message, click on Yes.
  16. On the next window, click OK.
  17. Find the Task List window, then double-click on the description.
  18. On the Startup Object, click on the item (Hello World.frmHelloWorld)
  19. Press F5 to run the program.
  20. Click on the button. You should see the message.

Part 3

As groups, create the following program that converts a temperature from Fahrenheit temperature to Celsius.

Decide the names of each object (refer to the GUI below).

Create flowchart, algorithm, pseudocode. Be sure to test the logic and the algorithm. Save the files in the FtoC folder.

If you get an error, take a look at the Trouble Shooting Tips page.

What is the text in green color for?

Create flowchart, algorithm, and pseudocode. Of course, it is in a reverse order since planning should have taken before coding the program. But it is a good practice creating the design after coding the program.

Part 4

As groups, create the following program that converts from Celsius temperature to Fahrenheit. Save the files in the FtoC folder.

Decide the names of each object (refer to the GUI below).

The formula is: tempF = tempC * 9 / 5 + 32

Create flowchart, algorithm, pseudocode. Be sure to test the logic and the algorithm.

One group will give a presentation.

Part 5

The Problem: A probe sent to Mars is about to crash due to programming error. The navigation control unit is in SEA unit (inches and feet) while the navigation software is written in metric system. Write a program that will convert measurement in meters into inches.