Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
26 views2 pages

Slab Calculation Programs

The document describes a Java program that calculates the rent for renting a CD based on the number of days. It defines a method 'calculateRent' which computes the total rent using a slab system: Rs. 10 for the first 2 days, Rs. 12 for the next 3 days, and Rs. 15 for any days beyond 5. The main method takes user input for the number of days and displays the total rent calculated by the method.

Uploaded by

revathyrenjit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views2 pages

Slab Calculation Programs

The document describes a Java program that calculates the rent for renting a CD based on the number of days. It defines a method 'calculateRent' which computes the total rent using a slab system: Rs. 10 for the first 2 days, Rs. 12 for the next 3 days, and Rs. 15 for any days beyond 5. The main method takes user input for the number of days and displays the total rent calculated by the method.

Uploaded by

revathyrenjit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Slab calculation programs

Write a program in Java to input the number of days a CD is rented.

Define a method calculateRent(int days) that receives the number of days as an argument and
returns the total rent. The rent is calculated as follows:

 For the first 2 days: Rs. 10 per day

 For the next 3 days: Rs. 12 per day

 For all days beyond 5: Rs. 15 per day

Calculate and return the total rent to the main method, where it should be displayed.

import java.util.Scanner;

public class CDRent


{

public static int calculateRent(int days)


{
int rent = 0;

if (days <= 2)
{
rent = days * 10;
} else if (days <= 5)
{
rent = (2 * 10) + (days - 2) * 12;
} else
{
rent = (2 * 10) + (3 * 12) + (days - 5) * 15;
}

return rent;
}

public static void main()


{
Scanner sc = new Scanner(System.in);
System.out.print("Enter number of days CD is rented: ");
int days = sc.nextInt();

int totalRent = calculateRent(days);

System.out.println("Total rent for " + days + " days is: Rs. " +
totalRent);
}
}

🧾 Variable Description

Variable Name Data Type Description

sc Scanner Scanner object to take input from the user

days int Number of days the CD was rented

rent int Calculated rent based on slab

Rent returned by the method and displayed


totalRent int
in main()

You might also like