-
Notifications
You must be signed in to change notification settings - Fork 0
Assignment-5 added #4
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
nitintayal008
wants to merge
5
commits into
main
Choose a base branch
from
Assignment-5
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
5 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,97 @@ | ||
| import { Actions } from './ErrorHandler'; | ||
|
|
||
| const StatusEnum = { | ||
| isCarBreakFail: true, | ||
| isCollision: false, | ||
| isEnvironmental: false, | ||
| isAbruptlyStop: false | ||
| }; | ||
|
|
||
| import { | ||
| CarAbrupltyStopException, | ||
| CollisionAccidentException, | ||
| HitAndRunAccidentException, | ||
| EnvironmentalAccidentException, | ||
| CarBrakeFailException | ||
| } from './exceptions'; | ||
|
|
||
| try { | ||
| driveCar(); | ||
| } catch (e) { | ||
| if (e instanceof CarBrakeFailException) { | ||
| console.log("Car Brake Fail Exception occurred."); | ||
| handleBreakFailDamage(); | ||
| } else if (e instanceof CollisionAccidentException) { | ||
| console.log("Collision Accident Exception occurred."); | ||
| handleCollisionAccident(); | ||
| } else if (e instanceof EnvironmentalAccidentException) { | ||
| console.log("Environmental Accident Exception occurred."); | ||
| handleNatureRelatedAccident(); | ||
| } else if (e instanceof HitAndRunAccidentException) { | ||
| console.log("Hit and Run Accident Exception occurred."); | ||
| handleHitAndRunAccident(); | ||
| } else if (e instanceof CarAbrupltyStopException){ | ||
| console.log("Car Abruplty Stop Exception occurred."); | ||
| abrupltyException(); | ||
| } else { | ||
| console.error("An error occurred:", e.message); | ||
| } | ||
| } finally { | ||
| checkAndReset(); | ||
| } | ||
|
|
||
| function driveCar() { | ||
| if (StatusEnum.isCarBreakFail) { | ||
| throw new CarBrakeFailException( | ||
| "Car Break Fail due to NonService of car, Have proper service" | ||
| ); | ||
| } else if (StatusEnum.isCollision) { | ||
| throw new CollisionAccidentException( | ||
| "Collision with another vehicle occurred." | ||
| ); | ||
| } else if (StatusEnum.isAbruptlyStop) { | ||
| throw new CarAbrupltyStopException( | ||
| "Automatically stop and not starting." | ||
| ); | ||
| } else if (StatusEnum.isEnvironmental) { | ||
| throw new EnvironmentalAccidentException( | ||
| "Environmental conditions such as thunderstorm. Drive with caution." | ||
| ); | ||
| } else { | ||
| throw new HitAndRunAccidentException("Hit and run incident happened."); | ||
| } | ||
| } | ||
|
|
||
| function handleBreakFailDamage() { | ||
|
mukulpalol16 marked this conversation as resolved.
|
||
| console.log(Actions.CALL_MECHANIC); | ||
| console.log(Actions.CALL_TOW_TRUCK); | ||
| } | ||
|
|
||
| function abrupltyException() { | ||
| console.log(Actions.CHECK_ALL_BRAKE); | ||
| console.log(Actions.CALL_MECHANIC); | ||
| console.log(Actions.CALL_TOW_TRUCK); | ||
| console.log(Actions.SEEK_SHELTER); | ||
| } | ||
|
|
||
| function handleCollisionAccident() { | ||
| console.log(Actions.CALL_AMBULANCE); | ||
| console.log(Actions.ASSESS_INJURIES); | ||
| console.log(Actions.FILE_INSURANCE_CLAIM); | ||
| } | ||
|
|
||
| function handleHitAndRunAccident() { | ||
| console.log(Actions.CALL_AMBULANCE); | ||
| console.log(Actions.INSPECT_DAMAGE); | ||
| console.log(Actions.CALL_POLICE); | ||
| } | ||
|
|
||
| function handleNatureRelatedAccident() { | ||
| console.log(Actions.SEEK_SHELTER); | ||
| console.log(Actions.CALL_AMBULANCE); | ||
| console.log(Actions.FILE_INSURANCE_CLAIM); | ||
| } | ||
|
|
||
| function checkAndReset() { | ||
| console.log(Actions.CHECK_AND_RESET); | ||
| } | ||
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,12 @@ | ||
| export const Actions = { | ||
| CALL_MECHANIC: "Mechanic called to assess and repair the car damage.", | ||
| FILE_INSURANCE_CLAIM: "Insurance claim filed for the accident.", | ||
| CHECK_ALL_BRAKE: "Check all the brake.", | ||
| CALL_AMBULANCE: "Ambulance are being contacted.", | ||
| CALL_TOW_TRUCK: "Tow truck is on the way to clear the vehicle.", | ||
| ASSESS_INJURIES: "Assessing injuries and providing necessary medical assistance.", | ||
| INSPECT_DAMAGE: "Damage to the vehicle is being inspected.", | ||
| CALL_POLICE: "Police is being notified about the hit and run incident.", | ||
| SEEK_SHELTER: "Seeking shelter due to environmental conditions.", | ||
| CHECK_AND_RESET: "check everthing in the cars and reset it if requirred.", | ||
| }; |
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,42 @@ | ||
| class CarBrakeFailException extends Error { | ||
| constructor(message: string) { | ||
| super(message); | ||
| this.name = this.constructor.name; | ||
| } | ||
| } | ||
|
|
||
| class CollisionAccidentException extends Error { | ||
| constructor(message: string) { | ||
| super(message); | ||
| this.name = this.constructor.name; | ||
| } | ||
| } | ||
|
|
||
| class HitAndRunAccidentException extends Error { | ||
| constructor(message: string) { | ||
| super(message); | ||
| this.name = this.constructor.name; | ||
| } | ||
| } | ||
|
|
||
| class EnvironmentalAccidentException extends Error { | ||
| constructor(message: string) { | ||
| super(message); | ||
| this.name = this.constructor.name; | ||
| } | ||
| } | ||
|
|
||
| class CarAbrupltyStopException extends Error { | ||
| constructor(message: string) { | ||
| super(message); | ||
| this.name = this.constructor.name; | ||
| } | ||
| } | ||
|
|
||
| export { | ||
| CollisionAccidentException, | ||
| HitAndRunAccidentException, | ||
| EnvironmentalAccidentException, | ||
| CarBrakeFailException, | ||
| CarAbrupltyStopException | ||
| }; |
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.