• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

help please

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to do a program that determines whether a file of student records is in sorted order or not. This program should consist of two classes.
In the first class it should contain a main method that prompts the user for the name of the input file.If the file cannot be opened, it should continue to reprompt the user for the correct name, until the file can be opened. The file should be read and the program should verify that the file is in ascending order. If it is not, an appropriate error message should be displayed and the program should terminate. As the student records are read in they should be displayed on the screen.I only doing first class because im already getting an error, i wanted to to thid first before i move on to the secomd class method.

I admit this is a project but i need some guidance please..
here is the code that i just did:



Im getting an error : illegal start of expression

sorry im new to java, really trying to understand it..
please help .. thanks
[ February 08, 2006: Message edited by: jcie ching ]
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it would help if you posted the EXACT error message, in it's entirety.

usually, an error like this is a missing semi-colon or a missing/extra curly bracket. it's usually a line or two above where the error message says it has the problem.

that is where i would start looking.
 
jcie ching
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi thanks for your reply, i got to fix the error already but on the second part of the program where my most errors and confusion is going on..please help
I need to write a program that that reads in a student record from a file.
I need to use method compareTo that compares two student records. Only the names of the students should be compared. The last name is more significant than the first one. The methid should return -1 if the first name is less than the second name, 0 if they are equal, and 1 if the first name is greater than the second one. A method equals that compares two students. Again only the names should be compared (as it is in the compareTo method.)

here what i got so far:



the error im getting are
invonvertible types - what does it mean?
thanks
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your "clone()" method, you've got

public Object clone()
{
Student otherStudent = (Student)other;
...

That "other" is referring to the member variable "other", which is a String. You can't cast a String to Student, as they're unrelated ("inconvertible" meaning you can't convert one to the other.)

clone(), by the way, is supposed to create a new object. I can't tell what it is that you're doing in your clone() method, but it doesn't look like you're creating a new Student. The best implementation of clone() would probably be something like



Note, also, that in overriding equals(), you've made a common mistake: you've changed the type of the parameter so that you've actually overloaded it rather then overriding it. The signature of equals() must be

public boolean equals(Object o)

Finally, I can't tell what the member "other" is for, but it's very confusing to have a member named "other" and have all your method parameters also named "other!"
 
jcie ching
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for your reply, i followed what u said and still some errors:



the error im getting is "class/interface expected"..
im just really new in java hope u dont mind =)
any more suggestions? thanks
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That error message usually means you have an extra close brace somewhere; I think I see one right after the compareTo() method.
 
jcie ching
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi i think i found the error but now im getting "illegal start of expression"
near "public int compareTo(Object o)" and "public boolean equals(Object o)"


any suggestions?
[ February 08, 2006: Message edited by: jcie ching ]
[ February 09, 2006: Message edited by: jcie ching ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic