You are on page 1of 9

Malm University

Programming Using Visual Basic, Basic Course

Assignment 6A OOP - Inheritance


Apus Post Office Version 1 Mandatory (for G or C)
(For VG, A, B Do only Version 2, Separate Document)
Farid Naisan
University Lecturer Department of Computer Sciences Malm University, Sweden

Programming Using Visual Basic, Basic Course

Assignment 6 V1

Assignment 6- Inheritance
1. Objectives
In the last module, we practiced with the first of the three important aspects of OOP, encapsulation. Now it is time to move forward and try the next concept, inheritance. Object inheritance helps to reuse code by creating a is a relation between objects of same type. The following topics are addressed in this assignment: Inheritance techniques in Visual Basic, Dynamic Binding Is a relation between objects Working with resources Tab Control

Farid Naisan

2(9)

Programming Using Visual Basic, Basic Course

Assignment 6 V1

2. Description
APU has recently established a new private postal service company (hereafter referred to as APO) to focus mainly on domestic business mail. Write a simple application for APO that helps the company to calculate prices based on the mail type, weight and the longest side of the mail objects. A prototype of the program at run-time is shown in the above figure. The services include delivery of letters, postcards and packages. APO groups the mail items into the following categories: 2.1 Envelope: Letters and other items that can be considered as letters fall under this category. Items must have a weight not exceeding 2000 grams (g) and the longest side is not greater than 500 millimeter (mm). The prices for letter postage, depending on their weight and the longest dimension, are summarized in Table 1. 2.1.1 2.1.2 2.1.3 En envelope having any side greater than 30 cm is classified as long envelope. Extra fee for long envelop is SEK 12.00. Envelopes weighing more than 3 kg or longest side greater than 1000 mm are not accepted as Envelope. Envelopes can be sent as Express mail and can be registered. An extra amount of SEK 95 is charged for Express mail and SEK 59 kg is charged for registered post (Swe: Rekommenderad).

2.2 Postcards: A postcard is treated as an envelope but with a fixed price of SEK 6.0. 2.3 Package: A package is a parcel with the dimensions length, width and height. In this version, only the longest dimension is to be considered. 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 Packages with the longest side exceeding 1200 mm will be charged an extra amount of SEK 137.50. Packages with a weight greater than 20 kg will charges en extra fee of SEK 50 for every excess kg. APO does not accept packages that weigh more than 300 kg or having a side greater than 5 m. A surcharge of SEK 300 is due when a package is to be sent as Express Mail. All packages are registered. Therefore no additional cost is charged.

Farid Naisan

3(9)

Programming Using Visual Basic, Basic Course

Assignment 6 V1

Table 1 Postage Prices for Envelope Weight (g) w <= 20 20 < w <= 100 100 < w <= 250 250 < w <= 500 500 < w <= 1000 1000 < w <= 2000 Any side > 30 mm Express Mail Registered Mail Amount (SEK) 6.00 12.00 24.00 36.00 48.00 72.00 +12.00 +95.00 +59.00

Table 2: Postage Prices for Package and Parcels Max Weight (kg) 3.00 5.00 10.00 15.00 20.00 Weight > 20.00 Longest side > 1200 mm Express Mail Registered Mail Amount (SEK) 150.00 180.00 230.00 280.00 325.00 50.00 /kg for weight > 20.00 +137.50 +300.00 Not applicable

3. The User Interface


3.1 A TabControl with two tabs (pages) is to be used in witch the first tab contains user interaction controls and the second page presents related information on the mail type selected on the first page. It also shows an image that may or may not have measurement symbols. The figure at right shows a case where the item Envelope is selected on the tab Cacl Price and it displays some information for envelopes. 3.2 Images can be drawn using Visual Studios Resource Editor (see the lecture document Working with Resources on the Module), or can be loaded from free Internet sites and embedded into the resource file of the project
Farid Naisan 4(9)

Programming Using Visual Basic, Basic Course

Assignment 6 V1

4. Requirements
4.1 The project figure shown here displays a suggestion of which classes you may need to write. The only requirement is to save all post-handling files in a separate folder (PostFiles here). Otherwise, you can apply your own solution provided you are using a good OOP design and writing a well-structured code, implementing inheritance and aggregation (when needed). 4.2 If you follow the instructions here, the class diagram below gives you an idea of how you can implement inheritance in this assignment.

4.3 Supply a constructor with at least one parameter, for example weight in the class MailItem. The class MailItem is intended to collect all data and methods that are general to all objects of mail. For training inheritance and constructors, it is required that MailItem does not contain a default constructor. 4.4 Use dynamic binding (see lecture material on the module) in the MainForm to create an object of the mail type, Poscard, Envelope or Package when the user makes a selection.

Farid Naisan

5(9)

Programming Using Visual Basic, Basic Course

Assignment 6 V1

4.5 Write a method GetPrice as overridable in the MailItem class and override it in its subclasses. In the MailItem class, this method can return 0.0. Every subclass provides its own implementation of the prices. The Envelop class has different prices for its objects than the package objects. 4.6 Write also an overridable method IsLong in the MailItem class and override it in the package class. Code the method in the MailItem class so it works for the Envelope and Postcard objects, i.e. it should return true if the longest side is greater than 30 mm. Override the method in the Package class so it returns true if the longest side is greater than 120 mm.

5. Help and guidance


4.7 In the paragraphs that follow, the contents of the classes shown in the class diagram earlier are copied from the project to give you an idea about the structure of the classes. However, remember that you are free to construct your classes and their contents your own way, as long as you follow a good programming style along the lines that we have emphasized in the previous assignments.

Farid Naisan

6(9)

Programming Using Visual Basic, Basic Course

Assignment 6 V1

The Resource File 5.1 A resource file is one that has a resx extension in VB, and is used for storing strings, icons, images, etc. To place strings in the resource file instead of inside code gives you the benefit of changing language of the user-interface, as well as easy maintenance. You can access the resources from your code by using the method call My.Rources.resourceName, where resourceName is the name of your resource. Here is an example of retrieving an image and strings from the resource file: picInfo.Image = My.Resources.letter lblInfo.Text = My.Resources.strLetterInfo lblInfo.Text += Environment.NewLine + My.Resources.strLetterInfo1

Farid Naisan

7(9)

Programming Using Visual Basic, Basic Course 6.1 You can add a resource, either create a new resource (image, icon, string, etc) using the Visual Studios Resource Editor, by right-clicking on My Project in Project Explorer and clicking Open. You can then add an existing image by browsing to the image file or create a new image using the simple drawing tools provided by the Resource Editor. A detailed description of working with resources in Visual Studio is found in the document Working with Resources in Visual Studio, available for downloading from the module on Its L.

Assignment 6 V1

TabControl Read about TabControls on the Internet or in your textbook. A TabCantrol has a number of pages. You can put new pages, edit pages or remove pages in the Properties Window in VS through the Collection property of the TabControl. 6.2 To detect which tab is the current tab, i.e. when the user clicks on a tab, the SelectedIndexChanged or the TabIndexChanged events can be handled.

6.3

Use dynamic-binding to create an object of the selected mail item. This will give your solution a polymorphic behavior. You declare an object reference (mail in the code clip below) at compile time. The exact type of the object is then not known and is determined at run time.

Farid Naisan

8(9)

Programming Using Visual Basic, Basic Course

Assignment 6 V1

The object can be a PostCard, an Envelope or Package instance determined at run time. The reference variable is assigned to hold the address of an object at runtime as coded below.

Other question? Use the forums for asking questions and discussing solutions.

6. Submission
Upload your project to Its L as previous assignments.

Good Luck!
Programming is fun. Never give up. Ask for help! Farid Naisan Course Responsible and Instructor
Farid Naisan 9(9)

You might also like