Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Lab Assignment #7 Create a Console Application called TicketCost that determines

ID: 3868983 • Letter: L

Question


Lab Assignment #7 Create a Console Application called TicketCost that determines the fine for student tickets as follows: Consider the situation of issuing speeding tickets on campus and determining the fines associated with the ticket All students are charged an initial $75.00 when ticketed. Additional charges are based on how much over the speed limit the ticket reads. On campus there is a 35 miles per hour (MPH) speed limit on most streets. Two roads are posted with a speed limit at 15 MPH. Fines are expensive on campus. After the initial $75 fee, an extra $87.50 is charged for every 5 MPH students are clocked over the speed limit. The traffic office feels seniors have been around for a while and should know better than to speed on campus. They add even more fees to their fine. At the same time, they try to cut freshmen a little slack. Seniors are charged an extra $50 when they get caught speeding, unless they are traveling more than 20 MPH over the speed limit. Then it is an additional $200 added to their fine. If freshmen are not exceeding 20 MPH over the speed limit, they get a $50 deduction off their fines. But, freshmen, sophomores, and juniors traveling over 20 MPH over the speed limit are fined an additional $100.

Explanation / Answer

Given below is the C# code for the question. The output for several test cases are shown below. Please don't forget to rate the answer if it helped. Thank you very much.

using System;

class Program
{
static void Main()
{
int rank, speedOver;
double cost;
Console.Write("What's your rank? (1=Freshman , 2=Sophomore, 3=Junior, 4=Senior) ");
rank = Convert.ToInt32(Console.ReadLine());
Console.Write("How many miles over the speed limit were you travelling? ");
speedOver = Convert.ToInt32(Console.ReadLine());
cost = GetTicketCost(rank, speedOver);
Console.WriteLine("The cost of the ticket is $" + cost);
}
  
public static double GetTicketCost(int rank, int speedOver)
{
double charges = 0;
if(speedOver > 0)
{
charges = 75; //initial charges
int numFives = speedOver / 5;
charges += numFives * 87.50;
if(rank == 4) //senior
{
if(speedOver > 20)
charges += 200; //200 if more than 20mph over speed limit
else
charges += 50;
}
else //for freshmen, sophomores, juniors
{
if(speedOver > 20)
charges += 100;
else if(rank == 1) //freshmen less than 20mph above speed limit
charges -= 50;
}
  
}
return charges;
}
}

output

What's your rank? (1=Freshman , 2=Sophomore, 3=Junior, 4=Senior) 1
How many miles over the speed limit were you travelling? 1
The cost of the ticket is $25   

What's your rank? (1=Freshman , 2=Sophomore, 3=Junior, 4=Senior) 1
How many miles over the speed limit were you travelling? 19
The cost of the ticket is $287.5   

What's your rank? (1=Freshman , 2=Sophomore, 3=Junior, 4=Senior) 1
How many miles over the speed limit were you travelling? 21
The cost of the ticket is $525   

What's your rank? (1=Freshman , 2=Sophomore, 3=Junior, 4=Senior) 2
How many miles over the speed limit were you travelling? 1
The cost of the ticket is $75