
Mastering Roblox Coding
By :

This exercise creates a simple police system that calculates a ticket price based on input.
System description
The police want a system where they can set a variable for the speed that a driver was going at, and a variable where they can set whether the driver had a license with them. There should be variables that determine the height of the ticket for each crime. There should also be two variables that state the maximum speed the driver is allowed to go and whether it is required for them to have a license. Combining this data should give one ticket price even if multiple crimes were committed. If there were no crimes committed, the ticket price would be 0
. The ticket price should be displayed in Output with the following text: Ticket Price: 0. The number depends on the height of the ticket.
Try to conclude what variables you need based on the system description. Again, analyzing a problem helps you to create a correct system.
Based on the system description, we can conclude the following facts:
speed
) and whether the driver had a license (hasLicense
) with them.ticketPrice
).Now that we know this, let us start programming our system. Follow these steps:
if
statement that checks whether the driver was going over the speed limit and applies the following:if
statement that checks whether the driver was violating the driving license rule and applies the following:print()
function to print the correct sentence. Refer to the software description for the required sentence.Execute your script and confirm that it works as described in the software description. Try to fix any errors that could show up in the Output frame. An example answer to this exercise can be found on the GitHub page for this book:
https://github.com/PacktPublishing/Mastering-Roblox-Coding/tree/main/Exercises