I am creating an ATM code that calculates how much denominations of USD/EURO (20s,10s,5s,1s, cents) will be withdrawn based on user input amount. I have already completed the USD calculations.. but now I have to convert all of this to EURO (*1.13 rate) and output it to a new .txt file (using PrintStream = new PrintStream).
I was considering multiplying the USD user input number by 1.13, then using this new total to repeat my calculations (writing an entire new set of declarations, then reprinting to .txt). My main struggle is finding a more simple way to do this and how to output everything to a new .txt.
Any advice is greatly appreciated!
import java.math.BigDecimal;
import java.io.PrintStream;
import java.util.Scanner;
import java.io.FileOutputStream;
import java.io.IOException;
public class ATM1 {
private static final BigDecimal FIVE = new BigDecimal("5");
private static final BigDecimal TEN = new BigDecimal("10");
private static final BigDecimal TWENTY = new BigDecimal("20");
private static final BigDecimal ONE_HUNDRED = new BigDecimal("100");
public static void main(String[] args) throws IOException {
System.out.print("Please enter USD withdrawal amount: ");
Scanner user = new Scanner(System.in);
BigDecimal usdTotal = user.nextBigDecimal();
BigDecimal billsOut;
BigDecimal bills20 = usdTotal.divide(TWENTY, 0, BigDecimal.ROUND_DOWN);
BigDecimal remainder10 = usdTotal.remainder(TWENTY);
BigDecimal bills10 = remainder10.divide(TEN, 0, BigDecimal.ROUND_DOWN);
BigDecimal bills5 = remainder10.subtract(bills10.multiply(TEN)).divide(FIVE, 0, BigDecimal.ROUND_DOWN);
BigDecimal remainder5 = remainder10.remainder(FIVE.setScale(0, BigDecimal.ROUND_DOWN));
BigDecimal bills1 = (remainder5.setScale(0, BigDecimal.ROUND_DOWN));
BigDecimal cents = usdTotal.setScale(2, BigDecimal.ROUND_DOWN).subtract(usdTotal.setScale(0, BigDecimal.ROUND_DOWN))
.multiply(ONE_HUNDRED);
System.out.println("Twenty Dollar Bills: " + bills20);
System.out.println("Ten Dollar Bills: " + bills10);
System.out.println("Five Dollar Bills: " + bills5);
System.out.println("One Dollar Bills: " + bills1);
System.out.println("Cents: " + cents.toBigInteger());
user.close();
PrintStream output = new PrintStream("euro.txt");
System.setOut(output);
}
}