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). -------------------------------------------------------------------------------------------------------- Note: I need to sort the outputs by Balances (greatest on top/lowest on bottom) Also, I need to add the name of the accounts. ============================================================== Current Code Output Accounts with a balance of at least $9000.00 (sorted by balance) Account Number Balance Cash Back? 201715141501700 9135.90 Yes 4508271490627227 9890.51 No 3573877643495486 9985.21 No 5100172198301454 9315.15 No 3551244602153760 9409.97 Yes 4405942746261912 9869.27 No 30526110612015 9866.30 No ------------------------------------------------------------------------------------------------- NEEDED CODE OUTPUT 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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

question Given:

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

 

--------------------------------------------------------------------------------------------------------

Note: I need to sort the outputs by Balances (greatest on top/lowest on bottom)

Also, I need to add the name of the accounts.

==============================================================

Current Code Output

Accounts with a balance of at least $9000.00 (sorted by balance)
Account Number Balance Cash Back?
201715141501700 9135.90 Yes
4508271490627227 9890.51 No
3573877643495486 9985.21 No
5100172198301454 9315.15 No
3551244602153760 9409.97 Yes
4405942746261912 9869.27 No
30526110612015 9866.30 No

-------------------------------------------------------------------------------------------------

NEEDED CODE OUTPUT

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

 

 

==========================================================================================================

File One:
import java.io.DataInputStream;
import java.io.EOFException;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Q4 {
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" , input);
System.out.print(" (sorted by balance)\n");
System.out.printf("%20s%10s%12s\n","q4.Q4.Account Number", "Balance", "Cash Back");
int results = 0;
ArrayList<Account> list = new ArrayList<>();
try {
FileInputStream fstream = new FileInputStream("accounts.dat");
DataInputStream inputFile = new DataInputStream(fstream);

boolean eof = false;
while (!eof)
{
try {
long cardNumber = inputFile.readLong();
double balance = inputFile.readDouble();
boolean cashBack = inputFile.readBoolean();
Account account = new Account(cardNumber, balance, cashBack);
list.add(account);
} catch (EOFException e) {
eof = true;
}
}
inputFile.close();
} catch (IOException e) {
e.printStackTrace();
}
for (Account x : list) {
if (x.getBalance() >= input && x.getBalance() <= 10000) {
System.out.printf("%20s%10.2f%12s\n" , x.getCardNumber(), x.getBalance(), x.getCashback());
results++;
}
}
System.out.printf("%34s results\n" , results);
}

public static class Account {
private long cardNumber;
private double balance;
private boolean cashback;

public Account(long cardNumber, double balance, boolean cashback)
{
this.cardNumber = cardNumber;
this.balance = balance;
this.cashback = cashback;
}

public long getCardNumber() {
return cardNumber;
}
public double getBalance(){
return balance;
}
public String getCashback() {
if (cashback)
return "Yes";
else
return "No";
}
}
}

=================================================================================================================

File Two


public class Account {
private long cardNumber;
private double balance;
private boolean cashback;

public Account(long cardNumber, double balance, boolean cashback)
{
this.cardNumber = cardNumber;
this.balance = balance;
this.cashback = cashback;
}

public long getCardNumber() {
return cardNumber;
}
public double getBalance(){
return balance;
}
public String getCashback() {
if (cashback)
return "Yes";
else
return "No";
}
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education