Create a program for a library whose Main() method asks the user to input the number of books checked out and the number of days they are overdue. Pass those values to a method that calculates and displays the library fine, which is 20 cents per book per day for the first seven days a book is overdue, then 50 cents per book per day for each additional day.
using System;
public class Program
{
public static void Main()
{
string noOfBks, noOfDys;
int numberOfBooks, numberOfDays;
Console.WriteLine("Enter the number of books checked out :");
noOfBks = Console.ReadLine();
Console.WriteLine("Enter the number of days overdue :");
noOfDys = Console.ReadLine();
// convert to integer
numberOfBooks = Convert.ToInt32(noOfBks);
numberOfDays = Convert.ToInt32(noOfDys);
Console.WriteLine("The fine amount is: {0}",calculateFine(numberOfBooks, numberOfDays) );
}
private static double calculateFine(int noOfOverdueBooks,int noOfOverdueDays)
{
double fineAmt = 0.0;
if (noOfOverdueDays <= 7)
fineAmt = noOfOverdueBooks * 0.20;
else if (noOfOverdueDays > 7)
fineAmt = 7 * 0.20 + (noOfOverdueDays - 7) * 0.50;
return fineAmt;
}
}
Comments
Leave a comment