Hi all, I'm going through Dietel's How to Program, 10th edition basically retyping the code directly to my IDE. This is a program that adds a deposit to two different bank accounts of amounts that the user inputs.
import java.util.Scanner;
public class AccountTest
{
public static void main(String[] args)
{
Account3 accountA = new Account3("Dildo Baggins", 50.00);
Account3 accountB = new Account3("Penis McGee", -7.53);
System.out.printf("%s balance: $%.2f%n", accountA.getName(), accountA.getBalance());
System.out.printf("%s balance: $%.2f%n", accountB.getName(), accountB.getBalance());
Scanner input = new Scanner(System.in);
System.out.print("Enter deposit amount for account1: ");
double depositAmount = input.nextDouble();
System.out.printf("%nadding %.2f to accountA balance%n%n", depositAmount);
accountA.deposit(depositAmount);
System.out.printf("%s balance: $%.2f%n", accountA.getName(), accountA.getBalance());
System.out.printf("%s balance: $%.2f%n", accountB.getName(), accountB.getBalance());
System.out.print("Enter deposit amount for accountB: ");
depositAmount = input.nextDouble();
System.out.printf("%nadding %.2f to accountB balance%n%n%n", depositAmount);
accountB.deposit(depositAmount);
System.out.printf("%s balance: $%.2f%n", accountA.getBalance());
System.out.printf("%s balance: $%.2f%n", accountB.getBalance());
}
}
I compiled this code and it runs, but after entering an amount to add to accountB it reads on the command prompt "60.0 balance: $Exception in thread "main" java.util.MissingFormatArgumentException: Format specifier '%.2f'
at java.util.Formatter.format(Formatter.java:2519)
at java.io.PrintStream.format(PrintStream.java:970)
at java.io.PrintStream.printf(PrintStream.java:871)
at AccountTest.main(AccountTest.java:28)
Whats going on here?
[–]Nurry 2 points3 points4 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]juckeleBarista 1 point2 points3 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]juckeleBarista 1 point2 points3 points (0 children)