Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 21st, 2004, 11:24 PM
Registered User
 
Join Date: Nov 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with Classes

Ok I'm taking a C# class and this is the first programming course I have ever taken so my questions will probably be dumb but well I can't figure some of things out sometimes so I have to ask.

The current issue is I have to take some information entered by a user and display it in a message box using two classes named Bonus and DVDObject. I'll post the code and if you could hopefully tell me where I'm screwing up I would greatly appreciate it. I've removed the IDE created code.

The DVDBurner namespace ( Not sure what its called. Its the
starting class )
Code:
      private DVDObject m_objDVD;
      private Bonus[] m_objBonusMat = new Bonus [ 3 ];
      private int m_intCount;

      // display information about DVD

      private void btnInformation_Click( 
         object sender, System.EventArgs e )
      {

         // output string
         string strInformation = m_objDVD.Title + "\r\n" +
            m_objDVD.Minutes + "\r\n" + m_objDVD.BonusMaterial; 

         lblDisplay.Text = strInformation; // clear Label

         // display output in a MessageBox
         MessageBox.Show( strInformation, "DVD Description",
            MessageBoxButtons.OK, MessageBoxIcon.Information );

      }// end method btnInformation_Click

      private void btnCreate_Click(object sender, System.EventArgs e)
      {

         string strMovieTitle = Convert.ToString ( txtTitle.Text );
         int intMovieMinutes = Int32.Parse ( txtMovieMinute.Text );

         string strDescription1 = Convert.ToString 
            txtDescription1.Text );
         int intMinutes1 = Int32.Parse ( txtMinutes1.Text );

         string strDescription2 = Convert.ToString (
            txtDescription2.Text );
         int intMinutes2 = Int32.Parse ( txtMinutes2.Text );

         string strDescription3 = Convert.ToString (
            txtDescription3.Text );
         int intMinutes3 = Int32.Parse ( txtMinutes3.Text );

         string[] strDescription = { strDescription1,
            strDescription2, strDescription3 };

         int[] intBonusMinutes = { intMinutes1, intMinutes2,
            intMinutes3 };

         for ( int intCount = 0; intCount <=
            m_objBonusMat.GetUpperBound(0); intCount++ )
         {
            m_objBonusMat[ intCount ] = new Bonus( 
               strDescription[ intCount ], 
               intBonusMinutes[ intCount ] );

         }

         for ( int intCount = 0; intCount <=
            m_objBonusMat.GetUpperBound(0); intCount++ )
         {
            m_objDVD = new DVDObject( strMovieTitle, intMovieMinutes,
               m_objBonusMat[ m_intCount ]);

         }

         btnInformation.Enabled = true;

      }
The Bonus class
Code:
      public class Bonus
      {

      //instance variables
      private string m_strDescription;
      private int m_intMinutes;

            public Bonus( string descriptionValue, int minuteValue )
            {
               Description = descriptionValue;
               Minutes = minuteValue;

            }

      public string Description //property Description
      {
         get
         {
            return m_strDescription;

         }

         set
         {
            m_strDescription = value;

         }

      } //end property Description

      public int Minutes  //property Minutes
      {
         get
         {
            return m_intMinutes;

         }

         set
         {
            m_intMinutes = value;

         }

      }//end property Minutes
The DVDObject class
Code:
      public class DVDObject
      {
          private string m_strTitle;
          private int m_intMinutes;
          private Bonus[] m_objBonusMaterial = new Bonus [ 3 ];
          private int m_intCount;

          public DVDObject( string titleValue, int minuteValue,
            Bonus bonusValue )
            {
               Title = titleValue;
               Minutes = minuteValue;
               BonusMaterial = bonusValue;

            }

      public string Title  //property Title
      {
         get
         {
            return m_strTitle;

         }

         set
         {
            m_strTitle = value;

         }

      }//end property Title

      public int Minutes //property Minutes
      {
         get
         {
            return m_intMinutes;

         }

         set
         {
            m_intMinutes = value;

         }

      }//end property Minutes

      public Bonus BonusMaterial //property Bonus
      {
         get
         {
            return m_objBonusMaterial[ m_intCount ];

         }

         set
         {
            for ( m_intCount = 0;
               m_intCount <= m_objBonusMaterial.GetUpperBound(0);
               m_intCount++ )
            {
               m_objBonusMaterial[ m_intCount ] = value;

            }

         }

      }//end property BonusMaterial
I think I am mostly screwed up in the DVDObject class. I can't figure out what to do there. Any help would be greatly appreciated.

Tony
 
Old November 22nd, 2004, 03:23 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Tony,

I haven't looked at your code yet, but I think it helps a great deal if you describe what the problem is. Are you getting an error, or are you not sure where to put what and where to ask the user for info?

You probably need a few methods on your form as well, to instantiate these classes, ask for input, do something useful with it and display the results back to the user.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old November 22nd, 2004, 08:55 AM
Friend of Wrox
 
Join Date: Feb 2004
Posts: 177
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Can you post the exact error you are getting or what kind of help do you need?


It is not how much we do,
but how much love we put in the doing.

-Mother Theresa





Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in calling classes in simple Servlet sanna231 J2EE 6 December 23rd, 2012 01:06 AM
HELP Problem With Classes nichola_x_rose ASP.NET 2.0 Basics 1 March 18th, 2007 03:35 AM
HELP Problem With Classes nichola_x_rose ASP.NET 2.0 Professional 0 March 17th, 2007 07:56 AM
Problem with the namespace & classes ayamas .NET Framework 2.0 2 November 25th, 2006 02:13 PM
Problem with classes hannahd JSP Basics 2 August 17th, 2006 04:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.