GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes help please Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "help please" Watch "help please" New topic
Author

help please

jcie ching
Greenhorn

Joined: Feb 08, 2006
Posts: 4
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 ]
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11351
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
jcie ching
Greenhorn

Joined: Feb 08, 2006
Posts: 4
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
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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!"


[Jess in Action][AskingGoodQuestions]
jcie ching
Greenhorn

Joined: Feb 08, 2006
Posts: 4
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
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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

Joined: Feb 08, 2006
Posts: 4
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 ]
 
GeeCON Prague 2014
 
subject: help please