-
Notifications
You must be signed in to change notification settings - Fork 0
Added solution for Car Crash problem #5
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
Poyam-ITT
wants to merge
4
commits into
main
Choose a base branch
from
Assignment5
base: main
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
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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,30 @@ | ||
| namespace CarApplication | ||
| { | ||
| public class Car | ||
| { | ||
| public void DrivingCar() | ||
| { | ||
| Random randomNumber = new Random(); | ||
| int randomDrivingEvent = randomNumber.Next(1, 10); | ||
|
|
||
| switch (randomDrivingEvent) | ||
| { | ||
| case 1: | ||
| throw new OutOfGasException("Car ran out of gas!"); | ||
| case 2: | ||
| throw new DriverUnderInfluenceException("Driver is intoxicated!"); | ||
| case 3: | ||
| throw new SpeedingException("Speed Alert!"); | ||
| case 4: | ||
| throw new MechanicalFailureException("Mechanical Issues Detected"); | ||
| case 5: | ||
| throw new DriverDistractedException("Driver Distracted Observation!"); | ||
| case 6: | ||
| throw new CarCrashException("Car crash occurred due to uncertain reasons!"); | ||
| default: | ||
| Console.WriteLine("No car crash occurred."); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } |
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,81 @@ | ||
| namespace CarApplication | ||
| { | ||
| public class CarExceptionHandler | ||
| { | ||
| public static void HandleOutOfGasException(OutOfGasException ex) | ||
| { | ||
| Console.WriteLine($"Car running out of gas: {ex.Message}"); | ||
| RefuelCar(); | ||
| } | ||
|
|
||
| public static void HandleDriverUnderInfluenceException(DriverUnderInfluenceException ex) | ||
| { | ||
| Console.WriteLine($"Alcohol detection system detected some illegal behaviours : {ex.Message}"); | ||
| DrinkAndDriveWarning(); | ||
| } | ||
|
|
||
| public static void HandleSpeedingException(SpeedingException ex) | ||
| { | ||
| Console.WriteLine($"Speed limit Detection detected High Speed: {ex.Message}"); | ||
| HighSpeedAlert(); | ||
| } | ||
|
|
||
| public static void HandleMechanicalFailureException(MechanicalFailureException ex) | ||
| { | ||
| Console.WriteLine($"Mechanical Issues found in the Car, contact mechanic: {ex.Message}"); | ||
| ContactNearestMechanic(); | ||
| } | ||
|
|
||
| public static void HandleDriverDistractedException(DriverDistractedException ex) | ||
| { | ||
| Console.WriteLine($"Sensors and cameras detected driver to be distracted, please focus: {ex.Message}"); | ||
| DriverBehaviourAlert(); | ||
| } | ||
|
|
||
| public static void HandleCarCrashException(CarCrashException ex) | ||
| { | ||
| Console.WriteLine($"Car crash occurred: {ex.Message}"); | ||
| CallEmergencyServices(); | ||
| } | ||
|
|
||
| public static void HandleUnexpectedException(Exception ex) | ||
| { | ||
| Console.WriteLine($"An unexpected error occurred: {ex.Message}"); | ||
| } | ||
|
|
||
| public static void SafeDriveCheck() | ||
| { | ||
| Console.WriteLine("Your car stopped, Did you reached safely?"); | ||
| } | ||
|
|
||
| private static void RefuelCar() | ||
| { | ||
| Console.WriteLine("Refueling the car..."); | ||
| } | ||
|
|
||
| private static void DrinkAndDriveWarning() | ||
| { | ||
| Console.WriteLine("DON'T DRINK AND DRIVE..."); | ||
| } | ||
|
|
||
| private static void HighSpeedAlert() | ||
| { | ||
| Console.WriteLine("SLOWER DOWN THE SPEED..."); | ||
| } | ||
|
|
||
| private static void ContactNearestMechanic() | ||
| { | ||
| Console.WriteLine("Searching for near by mechanic services..."); | ||
| } | ||
|
|
||
| private static void DriverBehaviourAlert() | ||
| { | ||
| Console.WriteLine("STOP GETTING DISTRACTED..."); | ||
| } | ||
|
|
||
| private static void CallEmergencyServices() | ||
| { | ||
| Console.WriteLine("Calling emergency services..."); | ||
| } | ||
| } | ||
| } |
|
Poyam-ITT marked this conversation as resolved.
|
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,46 @@ | ||
| namespace CarApplication | ||
| { | ||
| class CarOperationHandler | ||
| { | ||
| public static void Main() | ||
| { | ||
| try | ||
| { | ||
| var car = new Car(); | ||
| car.DrivingCar(); | ||
| } | ||
| catch (OutOfGasException ex) | ||
| { | ||
| CarExceptionHandler.HandleOutOfGasException(ex); | ||
| } | ||
| catch (DriverUnderInfluenceException ex) | ||
| { | ||
| CarExceptionHandler.HandleDriverUnderInfluenceException(ex); | ||
| } | ||
| catch (SpeedingException ex) | ||
| { | ||
| CarExceptionHandler.HandleSpeedingException(ex); | ||
| } | ||
| catch (MechanicalFailureException ex) | ||
| { | ||
| CarExceptionHandler.HandleMechanicalFailureException(ex); | ||
| } | ||
| catch (DriverDistractedException ex) | ||
| { | ||
| CarExceptionHandler.HandleDriverDistractedException(ex); | ||
| } | ||
| catch (CarCrashException ex) | ||
| { | ||
| CarExceptionHandler.HandleCarCrashException(ex); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| CarExceptionHandler.HandleUnexpectedException(ex); | ||
| } | ||
| finally | ||
| { | ||
| CarExceptionHandler.SafeDriveCheck(); | ||
| } | ||
| } | ||
| } | ||
| } |
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,32 @@ | ||
| namespace CarApplication | ||
| { | ||
| public class OutOfGasException : Exception | ||
| { | ||
| public OutOfGasException(string message) : base(message) { } | ||
| } | ||
|
|
||
| public class DriverUnderInfluenceException : Exception | ||
| { | ||
| public DriverUnderInfluenceException(string message) : base(message) { } | ||
| } | ||
|
|
||
| public class SpeedingException : Exception | ||
| { | ||
| public SpeedingException(string message) : base(message) { } | ||
| } | ||
|
|
||
| public class MechanicalFailureException : Exception | ||
| { | ||
| public MechanicalFailureException(string message) : base(message) { } | ||
| } | ||
|
|
||
| public class DriverDistractedException : Exception | ||
| { | ||
| public DriverDistractedException(string message) : base(message) { } | ||
| } | ||
|
|
||
| public class CarCrashException : Exception | ||
| { | ||
| public CarCrashException(string message) : base(message) { } | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.