I have been assigned to write a program which accepts a certain amount of money in standard form such as "7.53" and echo it as " You have entered 7 dollars and 53 cents", Then before any calculations I am supposed to convert that into an integer amount of cents (753). I wrote this program (shown below) but it only accepts an whole number as my input. What should I do to accept decimals and output successfully as integers?
import java.util.*; import javax.swing.*; public class CoinCounter { public static void main (String [] args){ Scanner sc = new Scanner(System.in); String userInput; int amount; int tooNie = 200; int looNie = 100; int quaRter = 25; int diMe = 10; int nickLes = 5; int peNNies = 1; int totalCoins = 0; userInput = JOptionPane.showInputDialog("Please enter an amount"); amount = Integer.parseInt(userInput); System.out.println("Enter amount in cents:"); amount=sc.nextInt(); System.out.println((amount / tooNie) + " – Toonies"); amount = amount % 200; System.out.println((amount / looNie) + " – Loonies"); amount = amount % 100; System.out.println((amount / quaRter) + " – Quarters"); amount = amount % 25; System.out.println((amount / diMe) + " – Dimes"); amount = amount % 10; System.out.println((amount / nickLes) + " – Nickles"); amount = amount % 5; System.out.println(amount + " – Pennies"); } }