0% found this document useful (0 votes)
33 views2 pages

Name: Mel Vincent Anonuevo SIN: 301167069 Date: Sept 14, 2021

The document defines a Cars class with properties for year, manufacturer, model, price, and whether it is drivable. It then creates 5 Cars objects with different values and prints them out to test the class. The Cars class constructor sets the property values, and ToString is overridden to return a formatted string of the property values.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views2 pages

Name: Mel Vincent Anonuevo SIN: 301167069 Date: Sept 14, 2021

The document defines a Cars class with properties for year, manufacturer, model, price, and whether it is drivable. It then creates 5 Cars objects with different values and prints them out to test the class. The Cars class constructor sets the property values, and ToString is overridden to return a formatted string of the property values.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

using System;

/*
* Name: Mel Vincent Anonuevo
* SIN: 301167069
* Date: Sept 14, 2021
*/

namespace Week01_Lab_Cars
{
class Program
{
static void Main(string[] args)
{
TestCars();
}
static void TestCars()
{

Cars a = new Cars(2018, "Audi", "R6", 30000, false);


Console.WriteLine(a);
Cars b = new Cars(2019, "BMW", "i3", 40000, true);
Console.WriteLine(b);
Cars c = new Cars(2020, "Chevrolet", "Traverse", 32000, true);
Console.WriteLine(c);
Cars f = new Cars(2021, "Ford", "F150", 35000, true);
Console.WriteLine(f);
Cars t = new Cars(2022, "Toyota", "4runner", 40000, true);
Console.WriteLine(t);
}

}
class Cars
{
private int year;
private string manufacturer;
private string model;
private bool isDrivable;
private double price;

//Constructor
/*public Cars(int yr, string manu, string mdl, double prce, bool isDrivable =
true)
{
year = yr;
manufacturer = manu;
model = mdl;
price = prce;
}*/
public Cars(int year, string manufacturer, string model, double price, bool
isDriveable = true)
{
this.year = year;
this.manufacturer = manufacturer;
this.model = model;
this.price = price;
this.isDrivable = isDriveable;
}

public override string ToString()


{
//return $"{year}, {manufacturer}, {model}, {price}, {isDrivable}";

return $"Year: {year}, Manufacturer: {manufacturer}, Model: {model}, Price:


{price}, IsDrivable?: {(isDrivable? "Drivable" : "Not Drivable")}";
}

You might also like