Given four values representing counts of quarters, dimes, nickels and pennies, output the total amount as dollars and cents. Output each floating-point value with two digits after the decimal point, which can be achieved as follows: System.out.printf("Amount: $%.2f\n", dollars); Ex: If the input is: 4 3 2 1 where 4 is the number of quarters, 3 is the number of dimes, 2 is the number of nickels, and 1 is the number of pennies, the output is: Amount: $1.41 For simplicity, assume input is non-negative.
LAB ACTIVITY 2.32.1: LAB: Convert to dollars 0/10 LabProgram.java Load default template. 1 import java.util.Scanner; 2 3 public class LabProgram 4 public static void main(String[] args) { 5 Scanner scnr = new Scanner(System.in); 6 7 /* Type your code here. */|| 8 9) Develop mode Submit mode Run your program as often as you'd like, before submitting for grading. Below, type any needed input values in the first box, then click Run program and observe the program's output in the second box Enter program input (optional) If your code requires input values, provide them here. Run program Input (from above) 1 LabProgram.java (Your program) Output (shown below) Program output displayed here

Answer :

MrRoyal

Answer:

Replace /* Type your code here. */ with the following lines of code

int quarter =scnr.nextInt();

int dime = scnr.nextInt();

int nickel = scnr.nextInt();

int penny = scnr.nextInt();

double dollars = quarter * 0.25 + dime * 0.1 + nickel * 0.05 + penny * 0.01;

System.out.printf("Amount: $%.2f\n", dollars);

System.out.print((dollars * 100)+" cents");

Explanation:

The next four lines declare the given currencies as integer

int quarter =scnr.nextInt();

int dime = scnr.nextInt();

int nickel = scnr.nextInt();

int penny = scnr.nextInt();

This line calculates the amount in dollars

double dollars = quarter * 0.25 + dime * 0.1 + nickel * 0.05 + penny * 0.01;

The next two lines print the amount in dollars and cents respectively

System.out.printf("Amount: $%.2f\n", dollars);

System.out.print((dollars * 100)+" cents");

Given four values representing counts of quarters, dimes, nickels and pennies, the total amount in dollars and cent can be represented as follows;

#1 quarters = 0.25 dollars

#1 dime  = 0.1 dollar.

#1 nickel = 0.05 dollars

#1 penny = 0.01 dollars

#quarters, dimes, nickels and pennies,

x = input("write your input here: ")

for i in x:

  quarters = 0.25*float(x[0])

  dime = 0.1*float(x[1])

  nickel = 0.05*float(x[2])

  penny = 0.01*float(x[3])

sum1 = quarters + dime + nickel + penny

print(round(sum1, 2))

Code explanation:

The commented section of the code is just the conversion rate of quarters, dime, nickel and penny to dollars.

  • Variable x is used to store the user's input.
  • Then, we loop through the users input
  • Then multiply each looped value by it conversion rate to dollars.
  • Finally, we sum the values and print the sum rounded to 2 decimal places as required.

learn more on python code here: https://brainly.com/question/24556911?referrer=searchResults

${teks-lihat-gambar} vintechnology
${teks-lihat-gambar} vintechnology

Other Questions