Class Project Developing Classes

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 559 Views - Last Post: 17 April 2012 - 10:49 PM Rate Topic: -----

#1 Swrzalinski  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 11-March 12

Class Project Developing Classes

Posted 15 April 2012 - 09:55 PM

Hello there I'm working on a class project where I have to create an item class with private attributes, public get and set methods for the attributes, and two non-access methods. I have two textbooks I work with. The first book is Clearly Visual Basic(Zak) and the second is Programming, Logic, and Design(Farrel). I've set my private attributes but I am having difficulty writing what I want to accomplish in the VB.net language. I am typing what I have in pseudo-code if I'm headed in the complete wrong direction please let me know. If I am correct help me convert to VB.net.

Class CD1
Declarations 
 private string cdName
 private string aristName
 private string musicGenre

public void setCdName(string name)
   cdName = name
return

public void setArtistName(string name)
   artistName = name
return 

public void setMusicGenre(string name)
   musicGenre = name 


Is This A Good Question/Topic? 0
  • +

Replies To: Class Project Developing Classes

#2 DimitriV  Icon User is offline

  • Don't try to save yourself… the circle is complete
  • member icon

Reputation: 544
  • View blog
  • Posts: 2,632
  • Joined: 24-July 11

Re: Class Project Developing Classes

Posted 15 April 2012 - 10:34 PM

It's good! I'll help you out here:
Class CD1
 
 private cdName As String
 private aristName As String
 private musicGenre As String

public sub setCdName(ByVal name As String)
   cdName = name
End Sub

public sub setArtistName(ByVal name As String)
   artistName = name
End Sub 

public sub setMusicGenre(ByVal genre As String)
   musicGenre = name 
End Sub
End Class


Was This Post Helpful? 1
  • +
  • -

#3 Swrzalinski  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 11-March 12

Re: Class Project Developing Classes

Posted 15 April 2012 - 10:43 PM

Good to hear thanks a lot will post further questions and or completed class when I reach that point.
Was This Post Helpful? 0
  • +
  • -

#4 Swrzalinski  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 11-March 12

Re: Class Project Developing Classes

Posted 16 April 2012 - 08:54 PM

New dilemma with my using classes project. I completed coding the classes, but after showing them to my instructor he suggested I try using the Public Property function instead of the Public Sub function...so that will explain the changes in the class code. I have two classes one titled Compact Disc and the other just titled DVD. I need to display the contents of two CD's based on my attributes within the class. They will need to display on my form load function. I'm having trouble figuring out where and what to code from here. I will post Compact Disc class code as well as my GUI/Form code so far.

Public Class CompactDisc
    Private _CdName As String
    Private _ArtistName As String
    Private _MusicGenre As String

    Public Property CDName As String
        Get
            Return _CdName
        End Get
        Set(ByVal value As String)
            _CdName = value
        End Set
    End Property
    Public Property ArtistName As String
        Get
            Return _ArtistName
        End Get
        Set(ByVal value As String)
            _ArtistName = value
        End Set
    End Property
    Public Property MusicGenre As String
        Get
            Return _MusicGenre
        End Get
        Set(ByVal value As String)
            _MusicGenre = value

        End Set
    End Property


Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim CD1 As New CompactDisc
        Dim CD2 As New CompactDisc

        CD1.CDName = ("From Under The Cork Tree")
        CD1.ArtistName = ("Fall Out Boy")
        CD1.MusicGenre = ("Rock")


Was This Post Helpful? 0
  • +
  • -

#5 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 956
  • View blog
  • Posts: 3,676
  • Joined: 02-July 08

Re: Class Project Developing Classes

Posted 16 April 2012 - 09:16 PM

Properties seems a better fit here as they are thing that describe the parts of the object. Once you define the object you need to figure out how to link them to controls/display them. One control that comes to mind is the ListView, another might be a DataGridView and my personal favorite would be to use GDI+ to draw them.
Was This Post Helpful? 1
  • +
  • -

#6 DimitriV  Icon User is offline

  • Don't try to save yourself… the circle is complete
  • member icon

Reputation: 544
  • View blog
  • Posts: 2,632
  • Joined: 24-July 11

Re: Class Project Developing Classes

Posted 16 April 2012 - 09:41 PM

Yeah, I was going to say to use Public Properties yesterday but I really wanted to see how the other part turned out first. I think I am agreeing with _HAWK_ on this one, either a ListView or a DataGridView.
Dim i1 As New ListViewItem("cd1")
i1.SubItems.Add(CD1.CDName)
i1.SubItems.Add(CD1.ArtistName)
i1.SubItems.Add(CD1.MusicGenre)

Dim i2 As New ListViewItem("cd2")
i2.SubItems.Add(CD2.CDName)
i2.SubItems.Add(CD2.ArtistName)
i2.SubItems.Add(CD2.MusicGenre)

MyListView.Columns.Add("Name")
MyListView.Columns.Add("Artist")
MyListView.Columns.Add("Genre")
MyListView.Items.Add(i1)
MyListView.Items.Add(i2)


That is worth a try. It will need more adapting, and be sure to check out the link I provided earlier in this post.
Was This Post Helpful? 1
  • +
  • -

#7 Swrzalinski  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 11-March 12

Re: Class Project Developing Classes

Posted 16 April 2012 - 10:11 PM

We haven't discussed ListView in class yet, but thanks for the link I'll do some reading and give this a shot. Not to mention I still have to figure out what two non-access methods I'd like to use some where in all of this.
Was This Post Helpful? 0
  • +
  • -

#8 DimitriV  Icon User is offline

  • Don't try to save yourself… the circle is complete
  • member icon

Reputation: 544
  • View blog
  • Posts: 2,632
  • Joined: 24-July 11

Re: Class Project Developing Classes

Posted 16 April 2012 - 10:22 PM

What do you mean by that?
Also, if you haven't used ListView maybe you should use something else. Like a ListBox maybe.
Dim i1 As String = cd1.CDName + " " + cd1.ArtistName + " " + cd1.MusicGenre
'repeat for no 2
ListBox1.Items.Add(i1)
ListBox1.Items.Add(i2)


It's just a matter of preference, I'm just thinking since you haven't covered ListView maybe you should'nt be using it :)
Was This Post Helpful? 1
  • +
  • -

#9 Swrzalinski  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 11-March 12

Re: Class Project Developing Classes

Posted 16 April 2012 - 11:11 PM

I just realized in all of this I totally forgot to mention I have a completely blank GUI. Which I suppose would make using the listbox appropriate.

ListBox1.Items.Add(CD1.CDName)
        ListBox1.Items.Add(CD1.ArtistName)
        ListBox1.Items.Add(CD1.MusicGenre)

I added that.. It still shows up in the list box.
Was This Post Helpful? 0
  • +
  • -

#10 DimitriV  Icon User is offline

  • Don't try to save yourself… the circle is complete
  • member icon

Reputation: 544
  • View blog
  • Posts: 2,632
  • Joined: 24-July 11

Re: Class Project Developing Classes

Posted 16 April 2012 - 11:18 PM

My solution would be better - yours would add on separate lines.
Was This Post Helpful? 1
  • +
  • -

#11 Swrzalinski  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 11-March 12

Re: Class Project Developing Classes

Posted 17 April 2012 - 09:30 PM

Is there a way to add a hyperlink to my list box as well a photo of some kind?
Was This Post Helpful? 0
  • +
  • -

#12 DimitriV  Icon User is offline

  • Don't try to save yourself… the circle is complete
  • member icon

Reputation: 544
  • View blog
  • Posts: 2,632
  • Joined: 24-July 11

Re: Class Project Developing Classes

Posted 17 April 2012 - 09:33 PM

Hyperlink? What do you mean by that?
Also, if you want to add pictures to it then ListBox is really not ideal.
But before I make assumptions, please elaborate.
Was This Post Helpful? 0
  • +
  • -

#13 Swrzalinski  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 11-March 12

Re: Class Project Developing Classes

Posted 17 April 2012 - 09:42 PM

I guess I should have said Link Label? But Not the basic Link Label that I can just slap onto the GUI is there a way to embed something like into the ListBox? Or am I expanding a bit far beyond the capabilities of the ListBox? See this assignment is an OOP assignment hence working with the classes, using the get and set methods, etc.. but my instructor had to make some kind of attempt at getting creative with this as well. So in my case having the CD/DVD classes I was thinking of either including links to the corresponding items or possibly the actual cover of the item.
Was This Post Helpful? 0
  • +
  • -

#14 DimitriV  Icon User is offline

  • Don't try to save yourself… the circle is complete
  • member icon

Reputation: 544
  • View blog
  • Posts: 2,632
  • Joined: 24-July 11

Re: Class Project Developing Classes

Posted 17 April 2012 - 09:53 PM

As far as I can tell, it's beyond the capabilities of a ListBox.
Was This Post Helpful? 0
  • +
  • -

#15 Swrzalinski  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 11-March 12

Re: Class Project Developing Classes

Posted 17 April 2012 - 09:55 PM

Maybe I should just go with the link label?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2