Writing classes help

Here is the entire source code for your console application:


Sub Main()
      'Create a new book
      Dim mybook as New Book()

      'Create a new page and set the new page's .SourceDoc
      'to the argument supplied in .Add()
      mybook.Pages.Add("c:\copyright.txt")
      
      'Display the .SourceDoc of the newly-added page
      Console.WriteLine(mybook.Pages(0).SourceDoc & " = c:\copyright.txt")

      'Display the read-only number of pages that have been added using Pages.Add()
      Console.WriteLine("Number of pages = " & mybook.Pages.Count & " = 1")

      'Delete the added page
      mybook.Pages(0).Remove()
End Sub


Now write the source for Book class that allows this console application to work. The first Console.WriteLine() should display "c:\copyright.txt = c:\copyright.txt". The second line displayed by Console.WriteLine() should display "Number of pages = 1 = 1".
ineedyourhelpAsked:
Who is Participating?
 
doobdaveConnect With a Mentor Commented:
Hi,

I would suggest that you need a collection, rather than an array.

A collection exposes a count property and add function by default.

In my opinion you need 3 classes:

Page Class
-- SouceDoc property (string)
-- New constructor takes in SourceDoc as parameter, and sets the property
-- Sub New (pSourceDoc)
-- me.SourceDoc=pSourceDoc
-- End Sub

PageCollection class
-- Inherits CollectionBase
-- Sub Add (ByVal pPage as Page)
-- Me.list.add(pPage)
-- End Sub

-- Sub Add(ByVal pSourceDoc as string)
-- Me.List.Add(New Page(pSourceDoc))
-- End Sub

Book class
-- Pages property
-- Public Property Pages as PageCollection
-- Set .....
-- Get .....

Hope to help,

David
0
 
Arthur_WoodCommented:
this looks very suspiciously like a homework assignment, and EE experts are NOT allowed to write answers to homework (see the EE Member guidelines)

What have you already tried?  We can ASSIST you in figuring this out (it is VERY elementary, and you should not need to ask us how to do this, if you have been paying attention in class).

AW
0
 
ineedyourhelpAuthor Commented:
I thought the easiest way would to show it in an assignment-like format. You are not doing homework. And as a side note, I'm really tired of hearing people in forums like this and in chat rooms making the assumption--erroneous, in this case--that the helpers are doing someone else's homework.
0
 
ineedyourhelpAuthor Commented:
If you would rather have me try to explain what I'm trying to do instead of asking in the prescribed way above, here, I hope this appeases you:

I have a class and need to add sub procedures to properties in the class. In the class, I want to be able to add new elements to an array in a manner that is much like adding elements to a ListView. In a ListView, there is a collection of Items, and each item has an .Add() and .Remove() method. That's what I'd like my class to do too--follow the VB.NET scheme of adding items.

Currently, my class has a public Property named FileName that is an array, and to add or remove items from the array, I have to use ReDim Preserve to resize the FileName of the project to a larger size, then set the new element in the array equal to the new FileName I want to add.

Alright, there's my attempt. If that doesn't make much sense, as I predicted it wont, then you may now understand why I wrote the question in the aforeposted format.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.