235k views
1 vote
Write a method named quarterstodollars. the method should accept an int argument that is a number of quarters, and return the equivalent number of dollars as a double. for example, if you pass 4 as an argument, the method should return 1.0; and if you pass 7 as an argument, the method should return 1.75.

2 Answers

1 vote

Answer:

def quarterstodollars():

quarters = float(input('Enter Quarter: '))

dollar = quarters / 4

return dollar

print(quaterstodollars())

Step-by-step explanation:

Programming language used is Python.

The program starts by first defining the function using the def keyword.

It then prompts the user to enter a quarter, the input is converted to a floating type number and it is stored in the quarters variable.

To calculate the dollar equivalent, the quarter is divided by 4.

Finally, the dollar value is returned.

The last line calls the method. check image to see the result.

Write a method named quarterstodollars. the method should accept an int argument that-example-1
User Weigreen
by
5.5k points
0 votes
public static void quarterstodollars(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter number of Quarters:");
System.out.print("Quarters:"); int Q1 = input.nextInt();
DecimalFormat fmt = new DecimalFormat("$#,###.##"); System.out.println("Total:"+fmt.format(calctotal(Q1)));}public static double calctotal(int Q1) { double total; total=(0.25 * Q1); return (total);}

Hope this helps!
User Aezell
by
6.5k points