Results 1 to 3 of 3

Thread: make this more object-oriented

  1. #1

    Thread Starter
    Hyperactive Member jeba's Avatar
    Join Date
    Feb 2000
    Posts
    265

    make this more object-oriented

    Hi,

    I have the following class. How would you rewrite this code to make it more object-oriented?
    Code:
    public class Vehicle
    	{
    		string type;
    		int numberOfWheels;
    		string colour;
    
    		public Vehicle (string myType)
    		{
    			type = myType;
    
    			if (type.Equals("bicycle"))
    			{
    				numberOfWheels = 2;
    			} 
    			else if (type.Equals("motorcycle"))
    			{
    				numberOfWheels = 2;
    			} 
    			else if (type.Equals("car"))
    			{
    				numberOfWheels = 4;
    			} 
    			else if (type.Equals("plane"))
    			{
    				numberOfWheels = 3;
    			} 
    			else if (type.Equals("boat"))
    			{
    				numberOfWheels = 0;
    			}
    		}
    
    		public void repaint (String newColour)
    		{
    			colour = newColour;
    		}
    
    		
    	}
    J£ßä

  2. #2
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    Uh, is that a homework assignment? Sounds like it is right out of a textbook

    Anyway, you would probably have car, boat, etc inherit from a base class (vehicle).

    Is that what you are looking for?

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Also why would you post C# work in the VB.NET section?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width