Answer to Question #199415 in C# for Nkhululeko Chabala

Question #199415

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.


1
Expert's answer
2021-05-30T07:18:06-0400
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;


	}	
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS