I am trying to call my methods within main but after entering my dollars and cents, the values don't change when I print them
import java.text.DecimalFormat;
import java.util.Scanner;
public class ChangeMachine {
public static void main(String[] args) {
System.out.println("Change is good");
int dollars = 0;
int cents = 0;
int toonie = dollars/2;
int loonie = dollars%2;
int quarter = cents/25;
int dime = (cents%25)/10;
int nickel = ((cents%25)%10)/5;
ChangeMachine.getAmountFromUser(dollars, cents);
ChangeMachine.calculateCoins(dollars, cents);
ChangeMachine.displayInvoice(dollars, cents, toonie, loonie, quarter, dime, nickel);
}
Method to input the dollars and cents Here I'm able to enter the amount but it won't appear when I try to display it
public static void getAmountFromUser(int dollars, int cents) {
Scanner input = new Scanner(System.in);
System.out.print("How many dollars? ");
dollars = input.nextInt();
System.out.print("How many cents? ");
cents = input.nextInt();
System.out.println();
input.close();
}
Method to calculate coins
public static void calculateCoins (int dollars, int cents){
DecimalFormat df = new DecimalFormat("#0.00");
double amount = dollars + cents/100.0;
System.out.println("$"+df.format(amount)+" requires:");
//-----Bonus-----
dollars=dollars+(cents+2)/100;
cents=(cents+2)%100;
//---------------
}
Method to display coins needed
public static void displayInvoice (int dollars, int cents, int toonie, int loonie, int quarter, int dime, int nickel){
System.out.println(toonie+" Toonies");
System.out.println(loonie+" Loonies");
System.out.println(quarter+" Quarters");
System.out.println(dime+" Dimes");
System.out.println(nickel+" Nickels");
}
}