stephwazzy
New member
- Joined
- Jun 26, 2019
- Messages
- 2
- Programming Experience
- Beginner
I am just beginning to learn programming and I am a bit stuck on how this code should look in Visual Studio. Please help! Seeing this solved as an example would help me with future object oriented programming!
class Vehicle
{
public string color;
}
{
return "This car is " + color;
}
- Create a project and add a class called Vehicle. In your project, select Add -> New Class. You should now have a file called Vehicle.cs.
- Add four properties to your class: color, make, model, speed. color,make, and model should be string properties. speed should be an int.
class Vehicle
{
public string color;
}
- Add a method called Describe(). Describe should output all of the properties of your class. Here is an example for Describe() that only outputs color:
{
return "This car is " + color;
}
- Here is example output:
- The Ford Focus is blue and is going 35 MPH.
- Add two methods. speedUp() and slowdown(). speedUp() should increment the value of the speed property. slowDown() should decrement the value of the speed property.
- Add a class called Car. Modify the class header for Car, so that it inherits from Vehicle:
- Add the following code to your Main method. Paste in your output below.
- Car myCar1 = new Car();
- myCar1.make = “Ford”;
- myCar1.model = “Focus”;
- myCar1.color = “blue”;
- Car myCar 2 = new Car();
- myCar1.make = “Chevy”;
- myCar1.model = “Cruze”;
- myCar1.color = “red”;
- for (int i = 0; i < 35; i++) {
- myCar2.speedUp();
- myCar1.speedUp();
- myCar 2.speedUp();
- }
- for (int i =0; i < 10; i++) {
- myCar2.slowDown();
- }
- myCar1.Describe();
- myCar2.Describe();