public class Bank{
public static OrderedCollection accounts = new OrderedCollection(1000);
public static void addAccounts(Account lov){
accounts.add(lov);
}
public static void removeAccounts(Account lov ){
accounts.remove(lov);
}
public static void getAccount(Account lov ){
accounts.get(lov);
}
public static String accounts(){
return accounts.toString();
}
}//end bank class
public class SavingAccount extends Account{
private String fname;
private String lname;
public SavingAccount(long accNumber, String fn, String ln, double balance){
super(accNumber, balance);
fname = fn;
lname = ln;
}
public SavingAccount(long accNumber){
super(accNumber);
}
public void setFirstName(String fn){ fname = fn;}
public void setLastName(String ln){lname = ln;}
public String getFirstName(){ return fname ;}
public String getLastName(){ return lname;}
}//end saving account
public class CheckingAccount extends Account{
private String fname;
private String lname;
public CheckingAccount(long accNum, String fn, String ln, double balance){
super(accNum, balance);
fname = fn;
lname = ln;
}
public CheckingAccount(long accNumber){
super(accNumber);
}
public void setFirstName(String fn){ fname = fn; }
public void setLastName(String ln){lname = ln; }
public String getFirstName(){ return fname ;}
public String getLastName(){ return lname;}
}//end saving account
import java.text.DecimalFormat;
//public class Account
public abstract class Account implements Comparable
{
//class Variables
private static int NumAccounts = 0;
private static final double Interest = 0.05;
//Instant Variables
protected long accountNumber;
protected double balance;
DecimalFormat x = new DecimalFormat( "$00,000.00" );//Format Balance
public Account( long accN, double bal ){//Constructor
accountNumber = accN;
balance = bal;
NumAccounts++;
}
public Account(long acc){
this(acc, 0.00);
//accountNumber = acc;
}
public static int GetNumAccounts(){
return NumAccounts;
}
public double getBalance(){
return balance;
}
public long getAccountNum(){
return accountNumber;
}
public void debit( double amount ){
if(balance >= amount){
balance -= amount;
}
}
public static void setNumAccounts(){//deincrement accounts
NumAccounts--;
}
public void credit( double amount ){
balance += amount;
}
public boolean equals(Object obj) {
if(!(obj instanceof Account)) return false;
Account acc = (Account) obj;
return accountNumber.equals(acc.accountNumber);//long cannot be dereferenced
}
public int hashCode() {
return accountNumber.hashCode();long cannot be dereferenced//long cannot be dereferenced
}
public int compareTo (Object obj) {
Account acc = (Account) obj;
return accountNumber.compareTo(acc.accountNumber);//long cannot be dereferenced
}
public String toString(){
String Str;
Str ="Account Number :" + accountNumber + "\n"+
"Account Balance :" + x.format( balance ) + "\n";
return Str;
}
}//End of abstract class Account
import java.io.*;
import java.util.*;
public class BankApp{
public static void main(String[] args)throws IOException{
Scanner input = new Scanner(new FileReader("bank.txt"));
while(input.hasNext()){
String line = input.next();
if(line.equals("ADD"))
{
String type = input.next();
if(type.equals("CA")){
//create checking account
Bank.addAccounts(new CheckingAccount(input.nextLong(), input.next(), input.next(), input.nextDouble()));
}else{
//create a savings account
Bank.addAccounts(new SavingAccount(input.nextLong(),input.next(), input.next(),input.nextDouble()));
}
//remove an account from the collection
}else if(line.equals("DEL")){
long p = input.nextLong();
Bank.removeAccounts(new SavingAccount(p));
//get an account from the collection
}else if(line.equals("GET")){
String ty = input.next();
if(ty.equals("SA")){
long x = input.nextLong();
Bank.getAccount(new SavingAccount(x));
}else{
long y = input.nextLong();
Bank.getAccount(new CheckingAccount(y));
}
//print the collection
}else if(line.equals("PRN")){
System.out.println("I am printing");
}
}//end while
}//end main
}//end class
Every thing is working ok except when I compile I am getting a "long cannot be defferened error." as indicated in the Account class. I am coverting the long accNumber to and object and then compate it to another object but it is not working out. How could I rectify this?