Question: Help with code in java here is my code import java.io.*; import java.util.*; public class AccountBalance { public static void main(String[] args) { Scanner keyboard

Help with code in java

here is my code

import java.io.*; import java.util.*; public class AccountBalance { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); System.out.println("Enter a balance"); double input = keyboard.nextDouble(); System.out.printf("Accounts with a balance of at least $%.2f (sorted by balance)%n", input); System.out.printf("%20s%20s%10s%10s%n","Name", "Account Number", "Balance", "Cash Back"); List list = new ArrayList<>(); try (DataInputStream inputFile = new DataInputStream(new FileInputStream("accounts-with-names.dat"))) { while (inputFile.available() > 0) { String name = inputFile.readUTF(); long accountNumber = inputFile.readLong(); double balance = inputFile.readDouble(); boolean cashBack = inputFile.readBoolean(); Account acc = new Account(name, accountNumber, balance, cashBack); list.add(acc); } } catch (IOException e) { e.printStackTrace(); } Collections.sort(list); int count = 0; for (Account acc : list) { if (acc.getBalance() >= input) { System.out.printf("%20s%20d%20.2f%12s%n", acc.getName(), acc.getAccountNumber(), acc.getBalance(), acc.hasCashBack() ? "Yes" : "No"); count++; } } System.out.printf("%d result%s%n", count, count == 1 ? "" : "s"); } } 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 am not displaying the right information as it isn't reading the correct information from the binary file

Enter a balance 9000ENTER Accounts with a balance of at least $9000.00 (sorted by balance) Name Account Number Balance Cash Back java.io.EOFException \tat java.base/java.io.DataInputStream.readFully(DataInputStream.java:203) \tat java.base/java.io.DataInputStream.readUTF(DataInputStream.java:614) \tat java.base/java.io.DataInputStream.readUTF(DataInputStream.java:570) \tat AccountBalance.main(AccountBalance.java:16) 0 results

this is my required output

Enter a balance 9000ENTER Accounts with a balance of at least $9000.00 (sorted by balance) Name Account Number Balance Cash Back Brand Hallam 3573877643495486 9985.21 No Paco Verty 4508271490627227 9890.51 No Stanislaw Dhenin 4405942746261912 9869.27 No Eachelle Balderstone 30526110612015 9866.30 No Reube Worsnop 3551244602153760 9409.97 Yes Tiphanie Oland 5100172198301454 9315.15 No Jordan Rylstone 201715141501700 9135.90 Yes 7 results

---

Enter a balance 8000ENTER Accounts with a balance of at least $8000.00 (sorted by balance) Name Account Number Balance Cash Back Brand Hallam 3573877643495486 9985.21 No Paco Verty 4508271490627227 9890.51 No Stanislaw Dhenin 4405942746261912 9869.27 No Eachelle Balderstone 30526110612015 9866.30 No Reube Worsnop 3551244602153760 9409.97 Yes Tiphanie Oland 5100172198301454 9315.15 No Jordan Rylstone 201715141501700 9135.90 Yes Anjela Himsworth 3573904891259172 8985.27 Yes Howie Royson 3581572129932389 8965.07 Yes Blinni Mattke 3549214734886202 8960.76 No Dorotea Nolli 6396392530990977 8790.59 Yes Carita Savill 6767642427889745 8738.77 No Mateo Mollene 5100174906912671 8659.35 Yes Cathleen Schurcke 4041598930132416 8596.39 Yes Adriana Bru 3574931681854879 8482.46 Yes Orlando Nutbeem 6372756913380048 8346.07 No Leland Vasilyev 6394213548410265 8249.76 No Ambrosi Fussie 3581429661693202 8207.40 Yes Valentine Montford 3533184590527943 8176.80 Yes Sarette Springell 5100146117467372 8161.69 Yes Rich Yakovl 490337929898976334 8099.58 Yes Conney Sizeland 3588215263928408 8036.12 Yes 22 results\

----

I am trying to read from a binary file and retrieve the information from it, however my code does not allow me to display the information that I need

this is the question:

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).

can an expert help with my java code, I have tried every prior answert to this question and none of them are able to display the names, account numbers, balances, cash back, and results that are required.

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 Databases Questions!