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
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";
}
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images