In: Computer Science
Create an application for a library and name it FineForOverdueBooks. TheMain() 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 named DisplayFine that displays the library fine, which is 10 cents per book per day for the first seven days a book is overdue, then 20 cents per book per day for each additional day.
The library fine should be displayed in the following format:
The fine for 2 book(s) for 3 day(s) is $0.60
The numbers will vary based on the input.
In order to prepend the $ to currency values, the program will need to use the CultureInfo.GetCultureInfo method. In order to do this, include the statement using System.Globalization; at the top of your program and format the output statements as follows: WriteLine("This is an example: {0}", value.ToString("C", CultureInfo.GetCultureInfo("en-US")));
CODE:
using System;
using static System.Console;
using System.Globalization;
public class FineForOverdueBooks
{
public static void Main()
{
// Write your main here.
}
public static void DisplayFine(int books, int days)
{
// Write your DisplayFine method here.
}
}
using System.IO;
using System;
using static System.Console;
using System.Globalization;
class FineForOverdueBooks
{
static void Main()
{
Console.WriteLine("Enter number of books:");
int b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter number of days:");
int d = Convert.ToInt32(Console.ReadLine());
DisplayFine(b,d);
}
public static void DisplayFine(int books, int days){
int amt=0;
if(days<=7){
amt=books*10*days;
}
else if(days>7){
amt=books*10*7+books*20*(days-7);
}
WriteLine("Amount Due: {0}", amt.ToString("C", CultureInfo.GetCultureInfo("en-US")));
}
}
Thank you! if you have any queries post it below in the comment section I will try my best to resolve your queries and I will add it to my answer if required. Please give upvote if you like it.