1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
AVprozaik [17]
4 years ago
5

(Solved—15 Lines) 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 liter or less have a $0.10 deposit, and drink containers holding more than one liter 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 dollar sign and always displays exactly two decimal places.
Computers and Technology
1 answer:
andrezito [222]4 years ago
4 0

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.

You might be interested in
What are the total number of rows and columns on a worksheet?.
Margaret [11]

Answer:

1,048,576 rows

Explanation:

hahha cause im smart

3 0
2 years ago
Read 2 more answers
When you ____ an exception, you send a message that an error has occurred to another part of the program.
jekas [21]
The correct answer is most definitely B
8 0
3 years ago
Read 2 more answers
Please select the word from the list that best fits the definition
Tasya [4]

Answer:

d

Explanation:

because it is

3 0
3 years ago
Read 2 more answers
A state government is attempting to reduce the digital divide. Which of the following activities has the greatest potential to c
Sveta_85 [38]

Answer:

The correct answer is

Working with technology companies to offer computing devices at discounted prices to individuals with reduced incomes

Explanation:

As per the question, state government is trying to reduce the digital divide which primarily exists because low income people do not have access to the digital devices. Hence, any step taken to help the low income people to get the digital device will be the best strategy of government to reduce the digital divide.

Thus, the correct answer is Working with technology companies to offer computing devices at discounted prices to individuals with reduced incomes

7 0
3 years ago
Question 1 of 40
Novay_Z [31]

Answer:

D. Federal Work-Study

Explanation:

8 0
4 years ago
Other questions:
  • Write a program that uses a 2-D array to store the highest and lowest temperatures for each month of the year. The program shoul
    14·1 answer
  • A web ______ is a computer that delivers requested webpages to your computer or mobile device.
    7·1 answer
  • (01.03 LC)
    9·1 answer
  • What is the best option for sharing Word documents on a Microsoft network because it provides finer degrees of versioning contro
    6·1 answer
  • The program is to be answered in Java Programming not C++ Please answer the following: Modify the BarChart program to accept the
    6·1 answer
  • Pls help will give brainlest​
    15·2 answers
  • What would be an ideal scenario for using edge computing solutions?
    10·1 answer
  • Explain the history of America ​
    14·2 answers
  • If the fluid level in a battery is below the separators<br> should be added but never add
    5·1 answer
  • Is each of the following method identifiers (a) legal and conventional, (b) legal but unconventional, or (C) illegal?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!