Question

1. Create an algorithm for a program that simulates a police radar gun. The algorithm should...

1. Create an algorithm for a program that simulates a police radar gun. The algorithm should read an automobile speed (in km/h) and print the message “Speeding” if the speed exceeds 60kmh. The algorithm should then also calculate the appropriate fine. If the speed is 5 km/hr or less over this limit, only issue a warning. $80 for more than 5 and no more than 10 kmh above the limit, $150 for more than 10 but no more than 20kmh above the limit, $500 for more than 20kmh above the limit. You should give some thought as to the type of data you are working with before beginning to designed your solution.

  1. (Design/Problem Solving exercise 2)

Read the notes at the end of this lab discussing how to create and apply test data. Use the test table template below and the test descriptions as hints to define suitable test data to test a program you will write.

Once you identify suitable inputs and have filled in this column then you should identify what outputs you expect. Also read the information at the end of this lab about selecting suitable test data.

Test #

Test Description

Inputs

Expected

Outputs

Algorithm Outputs

Program

Success/Failure

1

Not speeding but close.

2

Speeding but only just.

3

Speeding but still a warning.

4

$80 fine

5

Still an $80 but only just.

6

$150 fine.

7

Still a $150 fine but only just.

8

$500 fine.

9

Zero input

Test #

Test Description

Inputs

Expected

Outputs

Algorithm Outputs

Program

Success/Failure

10

Negative speed (this has no meaning).

11

Input of incorrect data type

12

Null input

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Police Radar Gun Simulation Algorithm:

Step 1: Start

Step 2: Declare variables Speed, Fine

Step 3: Initialize variables Speed<-0, Fine<-0

Step 4: Print message “Please enter the Speed: “

Step 5: Read the input from the user

Step 6: If the input is not a number or nothing is entered

                           Print “Please enter the speed in numbers only”

                           Go to Step 4

Step 7: If Speed is negative or ‘0’

                           Print “Invalid Speed entered. Wrong Input”

                           Go to Step 9

Step 8: If Speed > 60 kmh

                           8.1        Print “Speeding”

                            8.2        If    Speed <= 65 kmh

                                                       Print “Issue Warning”

                                         Else    If Speed <= 70 kmh

                                                                     Fine <- $80

                                                       Else If Speed <= 80 kmh

                                                                                   Fine <- $150

                                                                     Else    Fine <- $200

                           8.3        Print   “Calculated fine is = Fine”

              Else Print “Not Speeding”                                                    

Step 9: Stop

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

Test cases are executed in the following way for the algorithm.

Test Description Input Expected Outputs Algorithm Outputs Program Success/Failure
Not Speeding but close 59 kmh Not Speeding Not Speeding Success
Speeding but only just 61 kmh

Speeding

Issue Warning

Fine = 0

Speeding

Issue Warning

Fine = 0

Success
Speeding but still a warning 64 kmh

Speeding

Issue Warning

Fine = 0

Speeding

Issue Warning

Fine = 0

Success
$80 fine 67 kmh

Speeding

Fine = $80

Speeding

Fine = $80

Success
$150 fine 77 kmh

Speeding

Fine = $150

Speeding

Fine = $150

Success
Still a $150 fine but only just. 71 kmh

Speeding

Fine = $150

Speeding

Fine = $150

Success
$500 fine 90 kmh

Speeding

Fine = $500

Speeding

Fine = $500

Success
Zero Input 0 kmh Invalid Speed entered. Wrong Input Invalid Speed entered. Wrong Input Success in handling invalid input.
Negative Speed -30 kmh Invalid Speed entered. Wrong Input Invalid Speed entered. Wrong Input Success in handling invalid input.
Input of incorrect data type abce Please enter the speed in numbers only Please enter the speed in numbers only Success in handling invalid input.
Null input Please enter the speed in numbers only Please enter the speed in numbers only Success in handling invalid input.
Add a comment
Know the answer?
Add Answer to:
1. Create an algorithm for a program that simulates a police radar gun. The algorithm should...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Speeding Fine Calculator You have been hired by the police department of the city you live...

    Speeding Fine Calculator You have been hired by the police department of the city you live in to create a program to calculate the fine that a motorist could pay. If the motorist was travelling at or below the speed limit, there is no fine. If the motorist is travelling over the speed limit, the amount of the fine is determined based on the table below. The speed limit that will be entered is a multiple of 5 from 5...

  • Python "Speeding Violation Calculator" Program

    Please create this program in Python and run it making sure it works... Thank you SO much in advance. :)Design a program that calculates and displays the number of miles per hour over the speed limit that a speeding driver was doing. The program should ask for the speedlimit and the driver's speed. Validate the input as follows:* The speed limit should be at least 20, but not greater than 70*The driver's speed should be at least the value entered...

  • Must be written in JAVA Code Write a program that will read in a file of student academic credit data and create a list of students on academic warning. The list of students on warning will be written...

    Must be written in JAVA Code Write a program that will read in a file of student academic credit data and create a list of students on academic warning. The list of students on warning will be written to a file. Each line of the input file will contain the student name (a single String with no spaces), the number of semester hours earned (an integer), the total quality points earned (a double). The following shows part of a typical...

  • Please don't use a void fuction and this is a c++ question. Thanks Write a program...

    Please don't use a void fuction and this is a c++ question. Thanks Write a program that reads two input files whose lines are ordered by a key data field. Your program should merge these two files, writing an output file that contains all lines from both files ordered by the same key field. As an example, if two input files contain student names and grades for a particular class ordered by name, merge the information as shown below Using...

  • Java programming only Create a Java program that inputs a grade from the user. The grade input from the user will be an...

    Java programming only Create a Java program that inputs a grade from the user. The grade input from the user will be an integer. Once the input is stored, use an if-else-if block of code to determine the letter grade of the inputted integer grade. Do not use a bunch of if statements by themselves to solve this problem. You will print an error message for inputs greater than 100 and for inputs less than 0. Both errors must be...

  • C# programming Create an application that prompts the user for a storm windspeed in mph, then...

    C# programming Create an application that prompts the user for a storm windspeed in mph, then determines the correct typhoon category. The program must run all test cases of storm windspeed in one execution. Use a sentinel value to terminate the program. Do not assume a specific number of inputs. Determine the maximum storm windspeed value input. Note that the maximum must be evaluated within your program. You MAY NOT use C built in function. Output screenshot must include the...

  • Write a C program which computes the count of the prime and perfect numbers within a...

    Write a C program which computes the count of the prime and perfect numbers within a given limit Land U, representing the lower and upper limit respectively. Prime numbers are numbers that have only 2 factors: 1 and themselves (1 is not prime). An integer number is said to be perfect number if its factors, including 1 (but not the number itself), sum to the number. Sample Inputi: 1 100 Sample Outputs: Prime: 25 Perfect: 2 Sample Input2: 101 10000...

  • C code: hash program (use the Fowler-Noll-Vo (FNV) hash algorithm) This is a simple program that...

    C code: hash program (use the Fowler-Noll-Vo (FNV) hash algorithm) This is a simple program that you will use in the second part of the assignment. Details of this program is as follows. A hashing algorithm is simply an algorithm that maps data of an arbitrary size into a hash value of a fixed size. On your VM, you should have a program called ”md5sum”, which computes the MD5 hash of a file (or bytes taken from standard input). One...

  • Create an algorithm to count the number of 1’s in a 32-bit number. Implement the program in a high level language like...

    Create an algorithm to count the number of 1’s in a 32-bit number. Implement the program in a high level language like C or Java. It does not need to run for me, but the code should be included in a text document called FirstnameLastnameHLA3.txt along with your assignment submission. Implement the program in MIPSzy Assembly language. Use the high level code as comments to the right of the Assembly code as the textbook does. If you write that MIPSzy...

  • Create a complete pseudo-code program in C++ to do the following using the PseudoCode language developed...

    Create a complete pseudo-code program in C++ to do the following using the PseudoCode language developed in class using Absolute Addressing. There is 1 deliverable: 1. You should include the input cards shown below as a test. THE PROGRAM: First you will read in a value N which holds the number of values to be read in. (so if N is 20 then there will be 20 more cards to read in.) Read in N values into an array. Bubble-Sort...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT