Menu Close

Get deposit to recycle bottle in Java …ftc

In many jurisdictions a small deposit is added to drink containers to encourage people to recycle them. In one particular jurisdiction, drink containers holding one litre or less have a 0.10 deposit, and drink containers holding more than one litre have a 0.25 deposit.

Write a program that reads the number of containers of each size from the user. Your program should continue by computing and displaying the refund that will be received for returning those containers. Format the output so that it includes a rupees and always displays exactly two decimal places.

Input:
Bottle's Less than a litre = 23  
Bottle's More than a litre = 22

Output:
Refund for bottles = 7.80
import java.io.*;
import java.util.*;
public class temp{
  public static void main(String[] args){
    Scanner s=new Scanner(System.in);
    System.out.print("Less than one litre: ");
    int less = s.nextInt();
    System.out.print("More than one litre: ");
    int more = s.nextInt();
    double Refund = less*0.10 + more*0.25;
    System.out.println("Refund for Bottles =  "+String.format("%.2f",Refund));
	}
}

INPUT_1:
Less than one litre:  23
More than one litre:  22

OUTPUT:
Refund for Bottles = 7.80


INPUT_2:
Less than one litre:  157
More than one litre:  198

OUTPUT:
Refund for Bottles = 65.20


INPUT_3:
Less than one litre:  50
More than one litre:  60

OUTPUT:
Refund for Bottles = 20.00


INPUT_4:
Less than one litre:  500
More than one litre:  600

OUTPUT:
Refund for Bottles = 200.00


INPUT_5:
Less than one litre:  89
More than one litre:  90

OUTPUT:
Refund for Bottles = 31.40


INPUT_6:
Less than one litre:  63
More than one litre:  52

OUTPUT:
Refund for Bottles = 19.30


ILLUSTRATION

Executed using Javac in Linux Terminal