Question: I need help with my two codes in JAVA reading a binary file for multiple problems. I attached in my screenshot the correct output which

I need help with my two codes in JAVA reading a binary file for multiple problems. I attached in my screenshot the correct output which displays the correct spacing with total at the bottom. While my output in red which is incorrect is what my code is outputing. The question is: Ask the user for an account balance. Show, in descending order, all the accounts that have a balance greater than what the user input. Each entry is int, string, long, double, boolean (name length, name, credit card number, balance, cashback).****MY CODE****import java.io.*;
import java.util.Scanner;
public class BalanceAccount {
public static void main(String[] args) throws IOException {
FileInputStream basic = new FileInputStream("accounts-with-names.dat");
DataInputStream inputFile = new DataInputStream(basic);
boolean eof = false;
System.out.println("Enter a balance");
Scanner keyboard = new Scanner(System.in);
double input = keyboard.nextDouble();
System.out.println("Accounts with a balance of at least $"+ String.format("%.2f", input)+"(sorted by balance)");
System.out.printf("%20s%20s%15s%12s
", "Name", "Account Number", "Balance", "Cash Back");
int counter =0;
while (!eof){
try {
int nameLength = inputFile.readInt();
StringBuilder nameBuilder = new StringBuilder();
for (int i =0; i nameLength; i++){
char nameChar = inputFile.readChar();
nameBuilder.append(nameChar);
}
String name = nameBuilder.toString();
long cardnumber = inputFile.readLong();
double balance = inputFile.readDouble();
boolean cashback = inputFile.readBoolean();
if (balance > input){
System.out.printf("%20s%20d%15.2f%12s
", name, cardnumber, balance, (cashback ? "Yes" : "No"));
counter++;
}
} catch (EOFException e){
eof = true;
}
}
System.out.printf("%42s
", counter +" results");
}
}*** My code***class Account implements Comparable {
private String name;
private long accountNumber;
private double balance;
private boolean cashBack;
public Account(String name, long accountNumber, double balance, boolean cashBack){
this.name = name;
this.accountNumber = accountNumber;
this.balance = balance;
this.cashBack = cashBack;
}
public String getName(){
return name;
}
public long getAccountNumber(){
return accountNumber;
}
public double getBalance(){
return balance;
}
public boolean hasCashBack(){
return cashBack;
}
@Override
public int compareTo(Account other){
return Double.compare(other.balance, balance);
}
I need help with my two codes in JAVA reading a

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!