JAVA HELP 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 use string and char (instead of byte) to display the required info from a binary file    Enter a balance\n 9000ENTER Accounts with a balance of at least $9000.00 (sorted by balance)\n                 Name      Account Number   Balance Cash Back\n         Brand Hallam    3573877643495486   9985.21        No\n           Paco Verty    4508271490627227   9890.51        No\n     Stanislaw Dhenin    4405942746261912   9869.27        No\n Eachelle Balderstone      30526110612015   9866.30        No\n        Reube Worsnop    3551244602153760   9409.97       Yes\n       Tiphanie Oland    5100172198301454   9315.15        No\n      Jordan Rylstone     201715141501700   9135.90       Yes\n 7 results\n   i have this code so far 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(); // Create an ArrayList to store Account objects ArrayList accounts = new ArrayList<>(); try { // Open the binary file for reading DataInputStream inputstream = new DataInputStream(new FileInputStream("accounts-with-names.dat")); // Read the data from the file and store it in the ArrayList while (inputstream.available() > 0) { int nameLength = inputstream.readInt(); byte[] nameBytes = new byte[nameLength]; inputstream.readFully(nameBytes); String name = new String(nameBytes, "UTF-8"); long cardNumber = inputstream.readLong(); double balance = inputstream.readDouble(); boolean cashback = inputstream.readBoolean(); accounts.add(new Account(name, cardNumber, balance, cashback)); } // Sort the accounts by balance Collections.sort(accounts); // Print out the accounts with balance greater than or equal to input amount System.out.printf("Accounts with a balance of at least $%.2f (sorted by balance)%n", input); System.out.printf("%20s%20s%10s%12s%n", "Name", "Account Number", "Balance", "Cash Back?"); int count = 0; for (Account acc : accounts) { if (acc.getBalance() >= input) { System.out.printf("%20s%20d%10.2f%12s%n", acc.getName(), acc.getCardNumber(), acc.getBalance(), acc.hasCashback()); count++; } } // Print out the number of results found System.out.printf("%d results%n", count); // Close the input stream inputstream.close(); } catch (IOException e) { e.printStackTrace(); } } } class Account implements Comparable { private String name; private long cardNumber; private double balance; private boolean cashback; public Account(String name, long cardNumber, double balance, boolean cashback) { this.name = name; this.cardNumber = cardNumber; this.balance = balance; this.cashback = cashback; } public String getName() { return name; } public long getCardNumber() { return cardNumber; } public double getBalance() { return balance; } public boolean hasCashback() { return cashback; } @Override public int compareTo(Account other) { return Double.compare(this.balance, other.balance); } }   i cannot use this part int nameLength = inputstream.readInt(); byte[] nameBytes = new byte[nameLength]; inputstream.readFully(nameBytes); String name = new String(nameBytes, "UTF-8");   it produces an error i need to replace it with a char method instead to bring in the data from "accounts-with-names.dat" binary file

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
JAVA HELP
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 use string and char (instead of byte) to display the required info from a binary file 
 
Enter a balance\n
9000ENTER
Accounts with a balance of at least $9000.00 (sorted by balance)\n
                Name      Account Number   Balance Cash Back\n
        Brand Hallam    3573877643495486   9985.21        No\n
          Paco Verty    4508271490627227   9890.51        No\n
    Stanislaw Dhenin    4405942746261912   9869.27        No\n
Eachelle Balderstone      30526110612015   9866.30        No\n
       Reube Worsnop    3551244602153760   9409.97       Yes\n
      Tiphanie Oland    5100172198301454   9315.15        No\n
     Jordan Rylstone     201715141501700   9135.90       Yes\n
7 results\n
 
i have this code so far

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();
// Create an ArrayList to store Account objects
ArrayList<Account> accounts = new ArrayList<>();
try {
// Open the binary file for reading
DataInputStream inputstream = new DataInputStream(new FileInputStream("accounts-with-names.dat"));
// Read the data from the file and store it in the ArrayList
while (inputstream.available() > 0) {
int nameLength = inputstream.readInt();
byte[] nameBytes = new byte[nameLength];
inputstream.readFully(nameBytes);
String name = new String(nameBytes, "UTF-8");
long cardNumber = inputstream.readLong();
double balance = inputstream.readDouble();
boolean cashback = inputstream.readBoolean();
accounts.add(new Account(name, cardNumber, balance, cashback));
}
// Sort the accounts by balance
Collections.sort(accounts);
// Print out the accounts with balance greater than or equal to input amount
System.out.printf("Accounts with a balance of at least $%.2f (sorted by balance)%n", input);
System.out.printf("%20s%20s%10s%12s%n", "Name", "Account Number", "Balance", "Cash Back?");
int count = 0;
for (Account acc : accounts) {
if (acc.getBalance() >= input) {
System.out.printf("%20s%20d%10.2f%12s%n", acc.getName(), acc.getCardNumber(),
acc.getBalance(), acc.hasCashback());
count++;
}
}
// Print out the number of results found
System.out.printf("%d results%n", count);
// Close the input stream
inputstream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
class Account implements Comparable<Account> {
private String name;
private long cardNumber;
private double balance;
private boolean cashback;
public Account(String name, long cardNumber, double balance, boolean cashback) {
this.name = name;
this.cardNumber = cardNumber;
this.balance = balance;
this.cashback = cashback;
}
public String getName() {
return name;
}
public long getCardNumber() {
return cardNumber;
}
public double getBalance() {
return balance;
}
public boolean hasCashback() {
return cashback;
}
@Override
public int compareTo(Account other) {
return Double.compare(this.balance, other.balance);
}
}
 
i cannot use this part
int nameLength = inputstream.readInt();
byte[] nameBytes = new byte[nameLength];
inputstream.readFully(nameBytes);
String name = new String(nameBytes, "UTF-8");
 
it produces an error i need to replace it with a char method instead to bring in the data from "accounts-with-names.dat" binary file 
Expert Solution
Step 1

Please refer to the following step for the complete solution to the problem above.

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Concept of memory addresses in pointers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY