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, cashbackMY CODEimport java.io;
import java.util.Scanner;
public class BalanceAccount
public static void mainString args throws IOException
FileInputStream basic new FileInputStreamaccountswithnames.dat";
DataInputStream inputFile new DataInputStreambasic;
boolean eof false;
System.out.printlnEnter a balance";
Scanner keyboard new ScannerSystemin;
double input keyboard.nextDouble;
System.out.printlnAccounts with a balance of at least $ String.formatf inputsorted by balance;
System.out.printfssss
"Name", "Account Number", "Balance", "Cash Back";
int counter ;
while eof
try
int nameLength inputFile.readInt;
StringBuilder nameBuilder new StringBuilder;
for int i ; i nameLength; i
char nameChar inputFile.readChar;
nameBuilder.appendnameChar;
String name nameBuilder.toString;
long cardnumber inputFile.readLong;
double balance inputFile.readDouble;
boolean cashback inputFile.readBoolean;
if balance input
System.out.printfsdfs
name, cardnumber, balance, cashback "Yes" : No;
counter;
catch EOFException e
eof true;
System.out.printfs
counter results";
My codeclass Account implements Comparable
private String name;
private long accountNumber;
private double balance;
private boolean cashBack;
public AccountString 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 compareToAccount other
return Double.compareotherbalance, balance;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
