Question: In JAVA. I need help with my code!! It needs to display exactly as seen for all my problems with correct spacing. I only have

In JAVA. I need help with my code!! It needs to display exactly as seen for all my problems with correct spacing. I only have it outputing on number along with a couple people when I need it to output the list and give a total along with the correct spacing. 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, cashback).****MY CODE**** import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
public class BalanceAccount {
public static void main(String[] args) throws FileNotFoundException {
writedatFile();
ArrayList personList = new ArrayList();
File f = new File("accounts-with-names.dat");
Scanner sc = new Scanner(f);
while (sc.hasNext()){
String line = sc.nextLine();
String[] lineArr = line.split(",");
int nameLength = Integer.parseInt(lineArr[0]);
String name = lineArr[1];
long account = Long.parseLong(lineArr[2]);
double balance = Double.parseDouble(lineArr[3]);
boolean YN = lineArr[4].equalsIgnoreCase("true")? true : false;
personList.add(new Person(name, account, balance, YN));
}
sc = new Scanner(System.in);
System.out.println("Enter a balance");
double userEnteredBalance = sc.nextDouble();
System.out.println("Accounts with a balance of at least $9000.00(sorted by balance)");
System.out.printf("%20s%20s%10s%10s
", "Name", "Account Number", "Balance", "Cash Back");
int count =0;
for (Person p : personList){
if (p.getBalance()>= userEnteredBalance){
System.out.println(p.toString());
count++;
}
}
System.out.println(count +" results
");
}
private static void writedatFile(){
try {
FileWriter fileStream = null;
fileStream = new FileWriter(new File("accounts-with-names.dat"));
long val =3573877643495486L;
fileStream.write(12+","+ "Brand Hallam" +","+ val +","+9985.21+","+ "false");
fileStream.write("
");
val =4508271490627227L;
fileStream.write(10+","+ "Paco Verty" +","+ val +","+9990.51+","+ "false");
fileStream.write("
");
val =5452365845658756L;
fileStream.write(5+","+ "Tom C"+","+ val +","+8000+","+ "false");
fileStream.write("
");
fileStream.close();
} catch (IOException ex){
ex.getMessage();
}
}}
****MY CODE PERSON**** import java.io.IOException;
public class Person implements Comparable {
private long account;
private String name;
private double balance;
private boolean YN;
public Person(String name, long account, double balance, boolean YN){
this.account = account;
this.balance = balance;
this.YN = YN;
this.name = name;
}
@Override
public int compareTo(Person per){
int compare = name.compareTo(per.name);
if (compare ==0){
return 0;
} else if (compare 1){
return -1;
} else {
return 1;
}
}
public double getBalance(){
return balance;
}
@Override
public String toString(){
String yes_no;
String bs = String.valueOf(balance);
int b = bs.length();
if (!YN){
yes_no ="No";
} else {
yes_no = "Yes";
}
if (b 7){
bs = b +"0";
}
return String.format("%20s", name)+ String.format("%20s", account)+ String.format("%10s", bs)
+ String.format("%10s", yes_no);
}
}
In JAVA. I need help with my code!! It needs to

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