Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming

Reply
 
LinkBack Thread Tools
Old 10-28-07   #1 (permalink)
4.0 GHz
 
guitar22891's Avatar
 
intel nvidia

Join Date: Feb 2006
Location: Florida
Posts: 997

Rep: 46 guitar22891 is acknowledged by some
Unique Rep: 38
FAQs Submitted: 4
Trader Rating: 0
Default C# Property Methods, Constructors, Overload Constructors?

Hey, wondering if you could help with part of my C# program. How do I make a read/write property method, a default constructor, and an Overloaded Constructor? Here are the instructions if this helps:

Create a read/write property method for each of the class variables. Check the values of the arguments for the set methods that update the product number and the on hand quantity. Only update the class variables if the arguments values are greater than zero. Check the values of the arguments for the set methods that update the description and the on hand quantity. Only update the class variables if the arguments values are not blank (null or "").

Create a default constructor for the Product class. Initialize the product number and the on hand quantity to zero. Initialize the description to "no description". Initialize the unit of measure to "no unit of measure".

Create an overloaded constructor that takes four arguments - one each for the product number, description, on hand quantity, and unit of measure.
__________________
Future Upgrades:
  • Another 1gb of GSKILL DDR500
  • Better Graphics Card
Jesus is my Savior

System: My System
CPU
3.0E E0 Presscott @ 3.85
Motherboard
P4P800 SE
Memory
1GB DDR500 Gskill HZ
Graphics Card
FX5500 256mb 128bit AGP
Hard Drive
200GB Sata1.5 Maxtor
Sound Card
Onboard
Power Supply
400w FSP-PN
Case
Xoxide 5 in 1 combo
OS
Windows XP Home & Ubuntu
Monitor
19in Flat Panel
guitar22891 is offline   Reply With Quote
Old 10-28-07   #2 (permalink)
AMD Overclocker
 
decompiled's Avatar
 
amd nvidia

Join Date: Feb 2006
Location: Redsox Nation
Posts: 516

Rep: 50 decompiled is acknowledged by some
Unique Rep: 48
Hardware Reviews: 9
Trader Rating: 0
Default

It sounds like the professor wants you to create a program that has:

A constructor. This will create your object.

An overloaded constructor. This will allow you to create an object specifying something about the object.

An accessor. This will allow you to get information from the object.

A mutator. This will allow you to set some kind of information about the object.



For example:

Code:
using System;

public class TestClass
{
  private string MyColor = "yellow";

   public string Color
  {
     // Default Constructor
     Color()
     {
     }
     // Overloaded constructor - sets color from method call
     Color(String x)
     {
        set MyColor = x;
     }
     // Accessor - gets property of object
     get
     {
       return MyColor;
     }
     // Mutator - sets property of object
     set
     {
       MyColor = value;
     }
  }


  public static void Main()
  {
     TestClass c = new TestClass();
     Console.WriteLine(c.Color); // get
     c.Color = "blue";           // set
     Console.WriteLine(c.Color); // get
  }
}

Just curious... Are you a compsci student or is the just a class you have to take?

System: Slow Poke
CPU
AMD X2 4400
Motherboard
MSI K8N Diamond +
Memory
3gb TCC5
Graphics Card
eVGA 7900GS
Hard Drive
74gb Raptor + Raid 1 640's
Sound Card
Audigy SE
Power Supply
OCZ 520 PowerStream
Case
Antec P180
CPU cooling
Stock AMD
GPU cooling
Stock eVGA
OS
Vista x64
Monitor
Dell 1905FP
decompiled is offline   Reply With Quote
Old 10-28-07   #3 (permalink)
4.0 GHz
 
guitar22891's Avatar
 
intel nvidia

Join Date: Feb 2006
Location: Florida
Posts: 997

Rep: 46 guitar22891 is acknowledged by some
Unique Rep: 38
FAQs Submitted: 4
Trader Rating: 0
Default

Thanks for the help :] .. I'm just a 16yr old kid learning on my own, interested in programming. I'm just a beginner, but in the future I do want to go into the Computer Science field.
__________________
Future Upgrades:
  • Another 1gb of GSKILL DDR500
  • Better Graphics Card
Jesus is my Savior

System: My System
CPU
3.0E E0 Presscott @ 3.85
Motherboard
P4P800 SE
Memory
1GB DDR500 Gskill HZ
Graphics Card
FX5500 256mb 128bit AGP
Hard Drive
200GB Sata1.5 Maxtor
Sound Card
Onboard
Power Supply
400w FSP-PN
Case
Xoxide 5 in 1 combo
OS
Windows XP Home & Ubuntu
Monitor
19in Flat Panel
guitar22891 is offline   Reply With Quote
Old 10-28-07   #4 (permalink)
AMD Overclocker
 
decompiled's Avatar
 
amd nvidia

Join Date: Feb 2006
Location: Redsox Nation
Posts: 516

Rep: 50 decompiled is acknowledged by some
Unique Rep: 48
Hardware Reviews: 9
Trader Rating: 0
Default

Wonderful to hear. Are you starting with C# as your first language?

System: Slow Poke
CPU
AMD X2 4400
Motherboard
MSI K8N Diamond +
Memory
3gb TCC5
Graphics Card
eVGA 7900GS
Hard Drive
74gb Raptor + Raid 1 640's
Sound Card
Audigy SE
Power Supply
OCZ 520 PowerStream
Case
Antec P180
CPU cooling
Stock AMD
GPU cooling
Stock eVGA
OS
Vista x64
Monitor
Dell 1905FP
decompiled is offline   Reply With Quote
Old 10-28-07   #5 (permalink)
Security Sleuth
 
amd nvidia

Join Date: Jun 2006
Location: Sao Paulo/ Brazil
Posts: 129

Rep: 18 skip-br Unknown
Unique Rep: 17
Trader Rating: 1
Default

this?
Code:
public class Product
    {
        private int pNumber, quantity;
        private string description, unit;

        public Product()
        {
            this.pNumber = this.quantity = 0;
            this.description = "no description";
            this.unit = "no unit of measure";
        }

        public Product(int prN, int qtd, string desc, string un)
        {
            this.pNumber = prN;
            this.quantity = qtd;
            this.description = desc;
            this.unit = un;
        }

        public int _productNumber
        {
            get { return pNumber; }
            set { if (value > 0) pNumber = value; }
        }
        public int _quantity
        {
            get { return quantity; }
            set { if (value > 0) quantity = value; }
        }
        public string _description
        {
            get { return description; }
            set { if (value != null && value != "") description = value; }
        }
        public string _unit
        {
            get { return unit; }
            set { if (value != null && value != "") unit = value; }
        }
    }
public Product() <- Constructor
public Product(int prN, int qtd, string desc, string un) <- Overloaded
public int _[???] <- get/set
__________________
CPUz verified OC

System: My System
CPU
AMD64 4400+ X2
Motherboard
ASUS A8V Deluxe Rev 2.0
Memory
2 Gb DDR
Graphics Card
6800 GT
Sound Card
Sennheiser PC155
Power Supply
ZM460B-APS
Case
Casemall O2
CPU cooling
stock
GPU cooling
Fatality
OS
WIN XP PRO SP3
Monitor
Samsung 932BW
skip-br is offline   Reply With Quote
Old 10-28-07   #6 (permalink)
4.0 GHz
 
guitar22891's Avatar
 
intel nvidia

Join Date: Feb 2006
Location: Florida
Posts: 997

Rep: 46 guitar22891 is acknowledged by some
Unique Rep: 38
FAQs Submitted: 4
Trader Rating: 0
Default

No, first I explored visual Basic since I heard that was a good place to start. Right now its Java and C# on and off.
__________________
Future Upgrades:
  • Another 1gb of GSKILL DDR500
  • Better Graphics Card
Jesus is my Savior

System: My System
CPU
3.0E E0 Presscott @ 3.85
Motherboard
P4P800 SE
Memory
1GB DDR500 Gskill HZ
Graphics Card
FX5500 256mb 128bit AGP
Hard Drive
200GB Sata1.5 Maxtor
Sound Card
Onboard
Power Supply
400w FSP-PN
Case
Xoxide 5 in 1 combo
OS
Windows XP Home & Ubuntu
Monitor
19in Flat Panel

Last edited by guitar22891 : 10-28-07 at 12:55 PM.
guitar22891 is offline   Reply With Quote
Old 10-28-07   #7 (permalink)
AMD Overclocker
 
decompiled's Avatar
 
amd nvidia

Join Date: Feb 2006
Location: Redsox Nation
Posts: 516

Rep: 50 decompiled is acknowledged by some
Unique Rep: 48
Hardware Reviews: 9
Trader Rating: 0
Default

Just as a suggestion. Try and pick a single language for now. And really focus on it.

System: Slow Poke
CPU
AMD X2 4400
Motherboard
MSI K8N Diamond +
Memory
3gb TCC5
Graphics Card
eVGA 7900GS
Hard Drive
74gb Raptor + Raid 1 640's
Sound Card
Audigy SE
Power Supply
OCZ 520 PowerStream
Case
Antec P180
CPU cooling
Stock AMD
GPU cooling
Stock eVGA
OS
Vista x64
Monitor
Dell 1905FP
decompiled is offline   Reply With Quote
Old 11-02-07   #8 (permalink)
News Fiend
 
intel nvidia

Join Date: Mar 2007
Posts: 94

Rep: 9 kyotejones Unknown
Unique Rep: 9
Trader Rating: 0
Default

Java and c# are pretty similar. Just choose one to start with then you can break into the other after you understand the basics better.

As for your question "skip-br" seems to have got what the instructions were asking.
__________________
System: SCUD
CPU
Pentium C2D 2.4GHz
Motherboard
ASUS P5N32-E SLI
Memory
2x1Gb Balistix
Graphics Card
GeForce 7950 GT
Sound Card
SupremeFX (ADI 1988b)
Power Supply
ENERMAX Liberty 620W
Case
RAIDMAX SMILODON ATX
CPU cooling
ARCTIC COOLING Freezer 7
GPU cooling
Passive Heat Sink + CPU Fan
OS
Win XP Pro
Monitor
2x20" Samsung SyncMaster
kyotejones is offline   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -4. The time now is 02:26 AM.


Overclock.net is a Carbon Neutral Site Creative Commons License Internet Security By ControlScan

Terms of Service / Forum Rules | Privacy Policy | Advertising | Become an Official Vendor
Copyright © 2008 Shogun Interactive Development. Most rights reserved.
Page generated in 0.32248 seconds with 8 queries