forked from AustinCodingAcademy/csharp-workbook
-
Notifications
You must be signed in to change notification settings - Fork 0
Finished assignment #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Smangumb
wants to merge
1
commit into
master
Choose a base branch
from
CarLot
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>netcoreapp2.2</TargetFramework> | ||
| </PropertyGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
|
|
||
|
|
||
| namespace CarLot | ||
| { | ||
| class Program | ||
| { | ||
| static void Main(string[] args) | ||
| { | ||
| CarLot samCarlot = new CarLot("Sam's Carlot"); | ||
| CarLot lameCarlot = new CarLot("Lame Carlot"); | ||
| Truck truck1 = new Truck("B8D3F20", "Ford", "150", 15000, 7); | ||
| Truck truck2 = new Truck("K39C0W", "Chevy", "Silverado", 16000, 6); | ||
| Car car1 = new Car("Sedan", 4, "67BN21", "Nissan", "Altima", 14500); | ||
| Car car2 = new Car("Hatchback", 2, "KO92LO", "Honda", "Civic", 19450); | ||
| samCarlot.AddVehicle(truck1); | ||
| samCarlot.AddVehicle(car1); | ||
| lameCarlot.AddVehicle(truck2); | ||
| lameCarlot.AddVehicle(car2); | ||
| samCarlot.PrintInventory(); | ||
| lameCarlot.PrintInventory(); | ||
| } | ||
| } | ||
| public class CarLot | ||
| { | ||
| //name prop | ||
| string Name { get; set; } | ||
| //list <vehicle> | ||
| List<Vehicle> Vehicles = new List<Vehicle>(); | ||
|
|
||
| public CarLot(string name) | ||
| { | ||
| this.Name = name; | ||
| } | ||
| public void AddVehicle(Vehicle vehicle) | ||
| { | ||
| Vehicles.Add(vehicle); | ||
| } | ||
| public void PrintInventory() | ||
| { | ||
| System.Console.WriteLine($"There are {Vehicles.Count} vehicles"); | ||
| foreach (var vehicle in Vehicles) | ||
| { | ||
| vehicle.PrintDescription(); | ||
| } | ||
|
|
||
| } | ||
| } | ||
| public abstract class Vehicle | ||
| { | ||
| public abstract string LicenseNumber { get; set; } | ||
| public abstract string Make { get; set; } | ||
| public abstract string Model { get; set; } | ||
| public abstract double Price { get; set; } | ||
|
|
||
| public abstract void PrintDescription(); | ||
| } | ||
| public class Truck : Vehicle | ||
| { | ||
| //5 properties | ||
| int BedSize { get; set; } | ||
| public override string LicenseNumber { get; set; } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when you don't declare the Vehicle.LicenseNumber as abstract then you don't need to override it here. |
||
| public override string Make { get; set; } | ||
| public override string Model { get; set; } | ||
| public override double Price { get; set; } | ||
| public Truck(string licenseNumber, string make, string model, double price, int bedSize) | ||
| { | ||
| this.LicenseNumber = licenseNumber; | ||
| this.Make = make; | ||
| this.Model = model; | ||
| this.Price = price; | ||
| this.BedSize = bedSize; | ||
| } | ||
| public override void PrintDescription() | ||
| { | ||
| System.Console.WriteLine("The truck is a {0} {1} with the license plate {2}. It has a truck bed of {3}ft. It costs {4}", Make, Model, LicenseNumber, BedSize, Price); | ||
| } | ||
|
|
||
| } | ||
| public class Car : Vehicle | ||
| { | ||
| // 6 properties | ||
| string Type { get; set; } | ||
| int NumDoors { get; set; } | ||
| public override string LicenseNumber { get; set; } | ||
| public override string Make { get; set; } | ||
| public override string Model { get; set; } | ||
| public override double Price { get; set; } | ||
| public Car(string type, int numDoors, string licenseNumber, string make, string model, double price) | ||
| { | ||
| this.Type = type; | ||
| this.NumDoors = numDoors; | ||
| this.LicenseNumber = licenseNumber; | ||
| this.Make = make; | ||
| this.Model = model; | ||
| this.Price = price; | ||
| } | ||
| public override void PrintDescription() | ||
| { | ||
| System.Console.WriteLine("The car is a {0} {1} with the license plate {2}. It is a {3}. It has {4} doors. It costs {5}", Make, Model, LicenseNumber, Type, NumDoors, Price); | ||
| } | ||
|
|
||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to declare these properties abstract.