Respuesta :
Answer:
JAVA program is given below.
import java.util.Scanner;
public class Main
{
//static variables declared and initialized as required
static float deposit1 = 0.10f;
static float deposit2 = 0.25f;
static float refund1;
static float refund2;
static int num_one_lit;
static int num_more;
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number of containers of 1 liter or less: ");
num_one_lit = sc.nextInt();
System.out.print("Enter the number of containers of more than 1 liter: ");
num_more = sc.nextInt();
//refund computed based on user input
refund1 = num_one_lit*deposit1;
refund2 = num_more*deposit2;
//displaying refund
System.out.printf("Total refund amount for containers of 1 liter or less is $%.2f %n", refund1);
System.out.printf("Total refund amount for containers of more than 1 liter is $%.2f %n", refund2);
}
}
OUTPUT
Enter the number of containers of 1 liter or less: 5
Enter the number of containers of more than 1 liter: 2
Total refund amount for containers of 1 liter or less is $0.50
Total refund amount for containers of more than 1 liter is $0.50
Explanation:
1. Variables are declared at class level hence declared as static.
2. Variables holding deposit also initialized with the given values.
3. User input is taken for the number of containers in both categories.
4. The total value of refund is computed using the given values and user entered values.
5. The total refund is displayed to the user for both categories.
6. To display two decimal places always, variables to hold deposit and refund are declared as float.
7. The keywords used for decimals are %.2f %n. The %.2f keyword indicates two decimal places to be displayed in float variable, %n indicates a numeric value is to be displayed.
8. The printf() method is used to display the formatted output for refund amount.
9. The keywords used to display the formatted output is derived from C language.
10. All the code is written inside class and execution begins from the main() method.