Question

In: Computer Science

Write a method speedingTicket() that decides whether a driver should be given a ticket from a...

Write a method speedingTicket() that decides whether a driver should be given a ticket from a police officer. The method accepts three parameters: speed (i.e., car speed) as integer; limit (i.e., speed limit) as integer and a boolean named donut indicating whether or not the police officer has eaten a donut today. A police officer that has eaten a donut is happy, so he/she is less likely to give the driver a ticket.

Your method should display either “Give Ticket” or “No Ticket!” based on the following:

• TICKET: Driver’s speed is more than 20 over the speed limit, regardless of donut status.

• TICKET: Driver's speed is 5-20 over the speed limit and officer has not eaten a donut.

• NO TICKET: Driver's speed is 5-20 over the speed limit and officer has eaten a donut.

• NO TICKET: Driver’s speed is < 5 over the speed limit, regardless of donut status.

Sample Calls Output speedingTicket(58, 55, false) No Ticket!

speedingTicket(45, 30, false) Give Ticket

speedingTicket(100, 75, true) Give Ticket

speedingTicket(42, 35, true) No Ticket!

speedingTicket(30, 35, false) No Ticket! //write your method below including the method header

Solutions

Expert Solution

Python 3 code

============================================================================================

def speedingTicket(speed,limit,donut):
diff=speed-limit
if(diff>20):
status='Give Ticket'
elif(diff>=5 and donut == False):
status='Give Ticket'
elif(diff>=5 and donut == True):
status='No Ticket!'
elif(diff<5):
status='No Ticket!'
return status

print(speedingTicket(45, 30, False))
print(speedingTicket(100, 75, True))
print(speedingTicket(42, 35, True))
print(speedingTicket(30, 35, False))

============================================================================================

Output


Related Solutions

Given the main method of a driver class, write a Fraction class. Include the following instance...
Given the main method of a driver class, write a Fraction class. Include the following instance methods: add, multiply, print, printAsDouble, and a separate accessor method for each instance variable. Write a Fraction class that implements these methods: add ─ This method receives a Fraction parameter and adds the parameter fraction to the calling object fraction. multiply ─ This method receives a Fraction parameter and multiplies the parameter fraction by the calling object fraction. print ─ This method prints the...
Discuss how it should be evaluated whether the cost driver hours is the best cost driver...
Discuss how it should be evaluated whether the cost driver hours is the best cost driver for estimating the cost function.
Discuss whether an airline employee who was given a free airline ticket as a congratulations for...
Discuss whether an airline employee who was given a free airline ticket as a congratulations for a promotion which can be used on any flight in the Continental US with available seating (on a standby basis) must include the ticket value in gross income. Must they include the ticket value in gross income? EXPLAIN WHY OR WHY NOT. Assume the employee uses the ticket on a flight from New York City to Seattle and it is valued at $1,350.
Please write a Java method contains that checks whether the second given character array is contained...
Please write a Java method contains that checks whether the second given character array is contained in the first given character array. We require that both of the arrays are partially filled.
Write a simple airline ticket reservation program. The program should display a menu with the following...
Write a simple airline ticket reservation program. The program should display a menu with the following options: reserve a ticket, cancel a reservation, check whether a ticket is reserved for a particular person, and display the passengers. The information is maintained on an alphabetized linked list of names. In a simpler version of the program, assume that tickets are reserved for only one flight. In a fuller version, place no limit on the number of flights. Create a linked list...
A lottery ticket is given. For this lottery, five integer numbers are chosen from 1 to...
A lottery ticket is given. For this lottery, five integer numbers are chosen from 1 to 50, and the order doesn’t matter. You win the main prize of one million dollars if your ticket matches all five numbers drawn; you win a second prize of one thousand dollars if your ticket matches exactly four of the five numbers drawn; and otherwise you win nothing. a. What’s the probability that you win the main prize? b. What’s the probability that you...
IN JAVA Write a program with a method that returns an array. The method should accept...
IN JAVA Write a program with a method that returns an array. The method should accept as input a comma-delimited string with three values from a user. The array should store each value in a different element. Use Try..Catch error handling and print any failure messages, or print success from within method if the execution is successful (see Chapter 13 in the text). Call the method from the main method of the program to demonstrate its functionality by looping through...
Create method addUserInput Write a method called addUserInput(). The method should ask the user to input...
Create method addUserInput Write a method called addUserInput(). The method should ask the user to input two integers (one by one), add the two integers, and return the sum. By using java.util.Scanner to get user input; The method may not compile due to Scanner Class which need to add a "throws" statement onto the end of the method header because some lines may throw exceptions Refer to the Java API documentation on Scanner to figure out which specific Exception should...
Write a program in java to determine whether a given function F from the set {0,1,2,3,...,m}...
Write a program in java to determine whether a given function F from the set {0,1,2,3,...,m} to (0,1,2,3,...,n} is one-to-one and/or onto. The inputs to your program will be: - an integer m - an integer n, and - a two dimensional boolean array F of size (m+1) x (n+1), where F[ i , j ] = 1 if F(i) = j.
Write a driver to get a String input from keyboard and if the input string has...
Write a driver to get a String input from keyboard and if the input string has less than 10 characters, throw a StringTooShortException. public class StringTooShortException extends Exception {     //-----------------------------------------------------------------     // Sets up the exception object with a particular message.     //-----------------------------------------------------------------     public StringTooShortException()     {         super("String does not have enough characters");     } }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT