Hi,
I've written the below code as part of a University assignment, it compiled ok in Eclipse but returns the <identifier> expected
error when compiling via the command line. The error appears on lines 7, 8, 12, 13 and 20. Could anyone shed any light on why i'm getting it back?
And on a separate note, if anyone happens to know why the takeIn method on row 61 isn't unassigning a CD to a Person I'd love to know as I've no idea!
Thanks in advance.
import java.util.ArrayList;
import java.io.*;
public class CDStore implements Serializable{
String name;
ArrayList<CD> discsArray;
ArrayList<Person> peopleArray;
public CDStore(String name) {
this.name = name;
discsArray = new ArrayList<CD>();
peopleArray = new ArrayList<Person>();
}
public String getName() {
return name;
}
public ArrayList<CD> getDiscs() {
return discsArray;
}
public ArrayList<Person> getPeople() {
return peopleArray;
}
public void addDisc(CD aCD) {
this.discsArray.add(aCD);
}
public void removeDisc(CD aCD) {
this.discsArray.remove(aCD);
}
public void addPerson(Person aPerson) {
this.peopleArray.add(aPerson);
}
public void removePerson(Person aPerson) {
this.peopleArray.remove(aPerson);
}
public boolean takeOut(CD aCD, Person aPerson) {
//int out = 0;
int out;
if((out = discsArray.indexOf(aCD)) != 0)
{
CD cd = (CD)discsArray.get(out);
if(cd.person == null)
{
cd.person = aPerson;
discsArray.set(out, cd);
return true;
}
}
return false;
}
public boolean takeIn(CD aCD, Person aPerson) {
int in;
if((in = discsArray.indexOf(aCD)) != 0)
{
CD cd = (CD)discsArray.get(in);
if(cd.person == null)
{
cd.person = aPerson;
discsArray.set(in, cd);
return true;
}
}
return false;
}
public ArrayList<CD> getDiscsForPerson(Person aPerson) {
ArrayList<CD> discsForPerson = new ArrayList<CD>();
for (int index = 0; index < peopleArray.size(); index++)
discsForPerson.add(discsArray.get(index));
return discsForPerson;
}
public ArrayList<CD> getAvailableDiscs() {
ArrayList<CD> AvailableDiscs = new ArrayList<CD>();
for(int i = 0; i < discsArray.size(); i++)
if(discsArray.get(i).getPerson() == null) {
AvailableDiscs.add(discsArray.get(i));
}
return AvailableDiscs;
}
public ArrayList<CD> getUnavailableDiscs() {
ArrayList<CD> UnavailableDiscs = new ArrayList<CD>();
for(int i = 0; i < discsArray.size(); i++)
if(discsArray.get(i).getPerson() != null) {
UnavailableDiscs.add(discsArray.get(i));
}
return UnavailableDiscs;
}
public String toString() {
return "CD Library Name: " + name + "\n" + "Discs within the CD Store: " + discsArray + "\n" + "People within the CD store" + peopleArray;
}
public String getStatus(){
String s="CDS taken: " + getUnavailableDiscs() + "CDS not taken: " + this.getAvailableDiscs();
return s;
}
public void printStatus() {
System.out.println("CDS taken: " + getUnavailableDiscs() + "\n"+ "CDS not taken: " + getAvailableDiscs() + "\n");
}
public void saveCDStoreToSerialFile(String fileName)
{
try {
ObjectOutputStream objOut = new ObjectOutputStream (
new BufferedOutputStream (new FileOutputStream(fileName)));
try
{
objOut.writeObject(this);
objOut.writeObject(name);
objOut.writeObject(discsArray);
objOut.writeObject(peopleArray);
}
finally
{
objOut.close();
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
public static CDStore loadCDStoreFromSerialFile(String fileName)
{
CDStore store = null;
try {
ObjectInputStream os = new ObjectInputStream(
new BufferedInputStream(new FileInputStream(fileName)));
try {
Object obj = os.readObject();
if (obj instanceof CDStore) {
store = (CDStore) obj;
}
} finally {
os.close();
}
}
catch (Exception ex) {
System.out.println("File not found");
}
return store;
};
}