हिंदी

In a library, books were given to members for two weeks. Upon late return, they were charged at a rate as per following chart: Days Late (D) <=3 Next 3 days

Advertisements
Advertisements

प्रश्न

In a library, books were given to members for two weeks. Upon late return, they were charged at a rate as per following chart:

Days Late (D) Late Fine in ₹
<=3 ₹ 4 per day
Next 3 days ₹ 8 per day in this range
Next 3 days ₹12 per day in this range
Beyond 9 days ₹ 15 per day in this range

Input the number of days late. Calculate and print the amount of late fine to be paid.

कोड लेखन
Advertisements

उत्तर

import java.util.*;
class clLibrary
{
    void main()
    {
         Scanner sc = new Scanner(System.in);
         int days = 0, fine = 0;
         System.out.print("Days late :: ");
         days = sc.nextInt();
         if(days<=3
         {
             fine = 4;
         }
         else if(days <= 6)
         {
             fine = 4 + (days - 3) * 8;
         }
         else if(days <=9)
         {
             fine = 4 + 8+ (days – 6) * 12;
         }
         else
         {
             fine = 4 + 8 + 12 + (days -9) * 15;
         }
         System.out.print(" For " + days + " days late, fine is : "+ fine );
    }
}

Output:

Days late :: 7

For 7 days late, fine is: 24

shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 11: Programs Overall - Conditions [पृष्ठ २५१]

APPEARS IN

रुपा पंडित Computer Applications [English] Class 10 ICSE
अध्याय 11 Programs Overall
Conditions | Q 4. | पृष्ठ २५१
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×