Answer:
In Java:
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
float speedlimit, actualspeed;
String ddate;
int schoolzone;
System.out.print("Speed Limit: ");
speedlimit = input.nextFloat();
System.out.print("Actual Speed: ");
actualspeed = input.nextFloat();
System.out.print("Date: ");
ddate = input.nextLine();
System.out.print("School Zone (1-Yes): ");
schoolzone = input.nextInt();
float ticket = 75;
ticket += 6 * (actualspeed - speedlimit);
if(actualspeed - speedlimit > 30){
ticket+=160;
}
if(schoolzone == 1){
ticket*=2;
}
System.out.print("Date: "+ddate);
System.out.print("Speed Limit: "+speedlimit);
System.out.print("Actual Speed: "+actualspeed);
System.out.print("Ticket: "+ticket);
}
}
Step-by-step explanation:
See attachment for complete program requirements
This declares speedlimit and actualspeed as floats
float speedlimit, actualspeed;
This declares ddate as string
String ddate;
This declares schoolzone as integer
int schoolzone;
This prompts the user for speed limit
System.out.print("Speed Limit: ");
This gets the speed limit
speedlimit = input.nextFloat();
This prompts the user for actual speed
System.out.print("Actual Speed: ");
This gets the actual speed
actualspeed = input.nextFloat();
This prompts the user for date
System.out.print("Date: ");
This gets the date
ddate = input.nextLine();
This prompts the user for school zone (1 means Yes, other inputs means No)
System.out.print("School Zone (1-Yes): ");
This gets the input for schoolzone
schoolzone = input.nextInt();
This initializes ticket to $75
float ticket = 75;
This calculates the additional cost based on difference between speed limits and the actual speed
ticket += 6 * (actualspeed - speedlimit);
If the difference between the speeds is greater than 30, this adds 160 to the ticket
if(actualspeed - speedlimit > 30){
ticket+=160;
}
If it is in a school zone, this doubles the ticket
if(schoolzone == 1){
ticket*=2;
}
The following print the ticket information
System.out.print("Date: "+ddate);
System.out.print("Speed Limit: "+speedlimit);
System.out.print("Actual Speed: "+actualspeed);
System.out.print("Ticket: "+ticket);