cohort class compile errors

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2007
Posts: 6
Reputation: ntdaycott is an unknown quantity at this point 
Solved Threads: 0
ntdaycott ntdaycott is offline Offline
Newbie Poster

cohort class compile errors

 
0
  #1
Mar 4th, 2008
Hi i have made a student and cohrt collection class program
The compiler give me error: illegal start of expression line 46

The cohort class file:

import java.util.*;

public class Cohort {

private static int groupSize = 15;

private HashSet aCohort;

public Cohort()
{
aCohort = new HashSet();
}



public String add(Student aStudent)
{
if (aCohort.add(aStudent))

if (aCohort.add(aStudent))
{

return "success";
}

return "failure";
}



public String remove(String aSudent)
{
Iterator it = aCohort.iterator();
while (it.hasNext())
{
Student aStudent = (Student)it.next();
if (aStudent== aStudent.getName()) {
{
it.remove();
return "success";
}
}
return "failure";
}

private String update(aStudent aStudent)
{
if (remove(Student.getName()) == "success")
{
return add(aStudent);
}
return "failure";
}

public Student search(String aName)
{
Iterator it = aCohort.iterator();
while (it.hasNext())
{
Student aStudent = (Student)it.next();
if (aName == aStudent.getName())
{
return aStudent;
}
}
return null;
}




public String toString()
{
String s = new String();
Iterator it = aCohort.iterator();
while (it.hasNext())
{
Student aStudent = (Student)it.next();
s = s + aStudent.toString();
if (it.hasNext())
{
s = s + "\n";
}
}
return s;
}


public static void main(String args[])
{

Cohort aCohort = new Cohort();

Student aStudent = new Student("Nathan","Leicester Uk");
System.out.println("Add student to Cohort: " + aCohort.add(aStudent));
System.out.println(aCohort.toString());


Student bStudent = new Student("Steve","Manchester Uk");
System.out.println("Add student to Cohort: " + aCohort.add(bStudent));
System.out.println(aCohort.toString());


Any help would be greatly appreciated
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 164
Reputation: orko is an unknown quantity at this point 
Solved Threads: 10
orko orko is offline Offline
Junior Poster

Re: cohort class compile errors

 
0
  #2
Mar 4th, 2008
Which one is your line 46?
A Perfect World
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 224
Reputation: bugmenot is an unknown quantity at this point 
Solved Threads: 31
bugmenot bugmenot is offline Offline
Posting Whiz in Training

Re: cohort class compile errors

 
0
  #3
Mar 5th, 2008
your remove() method doesn't have a closing brace

perhaps this has to do with your two opening braces after the if
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 6
Reputation: ntdaycott is an unknown quantity at this point 
Solved Threads: 0
ntdaycott ntdaycott is offline Offline
Newbie Poster

Re: cohort class compile errors

 
0
  #4
Mar 5th, 2008
Originally Posted by orko View Post
Which one is your line 46?

sorry it is:

private String update(aStudent aStudent)
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 164
Reputation: orko is an unknown quantity at this point 
Solved Threads: 10
orko orko is offline Offline
Junior Poster

Re: cohort class compile errors

 
0
  #5
Mar 5th, 2008
won't it be like following:
  1. private String update(Student aStudent)
What is you object type in the input Student or aStudent?
A Perfect World
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 6
Reputation: ntdaycott is an unknown quantity at this point 
Solved Threads: 0
ntdaycott ntdaycott is offline Offline
Newbie Poster

Re: cohort class compile errors

 
0
  #6
Mar 5th, 2008
Originally Posted by orko View Post
won't it be like following:
  1. private String update(Student aStudent)
What is you object type in the input Student or aStudent?
this is the student class program:

public class Student {
private static int nextNumber=1;
private int number;
private String name;
private String address;

public Student(String aName,String anAddress)
{
number = nextNumber;
name = aName;
address = anAddress;
nextNumber++;
}

public void setName(String aName)
{
name = aName;
}

public void setAddress(String anAddress)
{
address = anAddress;
}

public static int getNextNumber()
{
return nextNumber;
}

public int getNumber()
{
return number;
}

public String getName()
{
return name;
}


public String getAddress()
{
return address;
}

public String toString()
{
return "Number: " + number + " Name: " + name + " Address: " + address;
}


public static void main(String args[]){
Student aStudent = new Student("Nathan","Leicester England");
System.out.println("Number: " +aStudent.getNumber());
System.out.println("Name: " +aStudent.getName());
System.out.println("Address: " +aStudent.getAddress());

Student bStudent = new Student("Martin","St Margerets College Leicester");

System.out.println("Number: " +bStudent.getNumber());
System.out.println("Name: " +bStudent.getName());
System.out.println("Address: " +bStudent.getAddress());

bStudent.setName("Steven");
bStudent.setAddress("Abby Park College Leicester");
System.out.println(bStudent.toString());
}
}




I am all very new to Java and are having trouble understanding the error messages.

Thanks again
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,503
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 521
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: cohort class compile errors

 
0
  #7
Mar 5th, 2008
Most likely you are missing a brace or semi-colon somewhere above that line. Check all of your code blocks for proper brace structure and make sure all of your statements have appropriate semi-colons.

Also, check your spelling errors in the remove() and update() methods and if you re-post any code, make sure you place [code ] tags around it. Unformatted code is a painful mess to read.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 6
Reputation: ntdaycott is an unknown quantity at this point 
Solved Threads: 0
ntdaycott ntdaycott is offline Offline
Newbie Poster

Re: cohort class compile errors

 
0
  #8
Mar 5th, 2008
Thanks for your help. I did find a loose curly bracket nd one spelling mistake. I now have 3 errors in the compiler all pointing to line 34:

[ while (it.hasNext()) ]

errors state: illegal start of type, <identifier> expected and ';' expected.

Thanks again for everyones help and advice
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,503
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 521
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: cohort class compile errors

 
0
  #9
Mar 5th, 2008
You still have an error with the block structure then, because there is nothing wrong with that line.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC