using java i need help to fix the code i have i have put all
using java i need help to fix the code i have. i have put all the code i have for the classes below the problem question.
Problem #3: (LinkedLists) We are going to create a LinkedList of Accounts. Create a Class called “AccLinkedList”, and store it in a file called “AccLinkedList.java”. This class will be similar to the example I handed out in class. Remember back in Lab #1, you created an Account Class. Pull that class into this lab. Add a next property. Then build an AccLinkedList class that will store Accounts in a LinkedList in Order by Balance. That is the Highest balance should be at the head of the List and the lowest balance should be at the end of the list. Also include a display() method, that displays this linked list. In the main create and add 5 Account objects to your LinkedList, then print out this LinkedList. Make up the data for each account. The LinkedList should be in order by Balance.
AccLinkedList.java
Account.java
InsufficientFundsException.java
Solution
AccLinkedList.Java
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
public class AccLinkedList {
public Account head = null;
public int count = 0;
public AccLinkedList() {
}
public static void main(String args[]){
Account a1;
a1 = new Account(2222, \"Frank\", 500.00);
Account a2;
a2 = new Account(2233, \"Jimmy\", 739.00);
Account a3;
a3 = new Account(1122, \"John\", 100.00);
Account a4;
a4 = new Account(0001, \"Puteho\", 250.00);
Account a5;
a5 = new Account(5656, \"James\", 50.00);
LinkedList ronl;
ronl = new LinkedList();
ronl.add(a1);//addItemAcc(a1);
ronl.add(a2);//addItemAcc(a2);
ronl.add(a3);//addItemAcc(a3);
ronl.add(a4);//addItemAcc(a4);
ronl.add(a5);//addItemAcc(a5);
Collections.sort(ronl,new BalanceCampare());
display(ronl);
}
public static void display(LinkedList list1){
System.out.println(\"Sorted list entries: \");
Iterator<Account> itr1=list1.iterator();
while(itr1.hasNext()){
itr1.next().display();
}
}
}
Account.Java:
public class Account {
private int acctNo;
private String owner;
private double balance;
public Account next;
public Account() {
acctNo = 00;
owner = \" \";
balance = 0.0;
}
public Account(int ac, String own, double bal) {
acctNo = ac;
owner = own;
balance = bal;
}
public void Deposit(double amount) {
balance = balance + amount;
}
public void Withdraw(double amount) {
try {
if (amount > balance) {
throw new InsufficientFundsException(balance);
} else
balance = balance - amount;
} catch (InsufficientFundsException e) {
System.out.println();
System.out.println(e);
}
}
public int getAcctNo() {
return acctNo;
}
public void setAcctNo(int ac) {
acctNo = ac;
}
public String getOwner() {
return owner;
}
public void setOwner(String own) {
owner = own;
}
public double getBalance() {
return balance;
}
public void setBalance(double bal) {
balance = bal;
}
public void display() {
System.out.println(\"Account Number = \" + getAcctNo());
System.out.println(\"Account Owner = \" + getOwner());
System.out.println(\"Account Balance = $\" + getBalance());
System.out.println();
}
public static void main(String args []){
Account a1;
a1 = new Account(2222, \"Frank\", 500.00);
a1.Deposit(100.00);
a1.Withdraw(900.00);
a1.display();
}
}
InsufficientFundsException.Java:
public class InsufficientFundsException extends Exception{
public InsufficientFundsException(double balance) {
System.out.println(\"you have insufficient funds, your current available balance is : $\"+balance);
}
}
BalanceCampare.Java:
class BalanceCampare implements Comparator<Account>{
public int compare(Account a1, Account a2) {
if(a1.getBalance() < a2.getBalance()){
return 1;
} else {
return -1;
}
}
}


