• 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

uml

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm taking a Java class. We did some UML diagrams in class and I must have copied it wrong. Here it is:
Student

- name : String
- id : int
- gpa : float

+ Student ()
+ Student ( n : String, i : int, g : float )
+ setName ( n : String ) : void
+ setId ( i : int ) : void
+ setGpa ( g : float ) : void
+ getName () : String
+ getId () : int
+ getGpa () : float
+ toString () : String

This is what I have:

Then I have StudentDemo:

I've got 11 or 12 errors.
I'd appreciate any help.
Thanks!
K

[Moderator edit: adjusted line number in listing to make them correspond to reported errors]

 
Ranch Hand
Posts: 109
1
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Out the top of my head:

a) Student one declaration needs a semi-colon at the end.
b) Student two needs a second " at Fred.
c) You try to print the students. Student one though has no values set to its properties (maybe this prints "null", don't recall right now)

UML has nothing to do with your question :P
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Always give the full details of the error messages. That usually makes it easier for us to answer. If you have difficulty copying the errors, look here.
 
Kathy Sigel
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for those replies. Sorry that I didn't add in the specifics. BTW, I did add a semicolon to the end of Student One. I just forgot to add it here.
My bad! LOL.
First error: Student.java:14: error: <identifier> expected
public Student(String n, i, g)
Second error:Student.java:14: error: <identifier> expected
public Student(String n, i, g)
Third error:Student.java:29: error: illegal start of expression
public void setGpa(float g)
Fourth error:Student.java:29: error: illegal start of expression
public void setGpa(float g)
Fifth error:Student.java:29: error: ';' expected
public void setGpa(float g)
Sixth error:Student.java:29: error: ';' expected
public void setGpa(float g)
Seventh error:Student.java:37: error: ';' expected
public int getId()
Eighth error:Student.java:39: error: class, interface, or enum expected
return id;
Ninth error:udent.java:41: error: class, interface, or enum expected
public float getGpa()
Tenth error:Student.java:45: error: class, interface, or enum expected
public String toString()

 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The constructor parameters on line 14 are not declared correctly. Go back to your notes or refer to the Java tutorials to see how to declare multiple parameters correctly.
 
Junilu Lacar
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The error message about getGpa setGpa is misleading but not uncommon for compilers to do. You just have to look at the method right before it to find where you are actually missing a semicolon.
 
Kathy Sigel
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for that info. I can't believe I didn't see those ones about the int i and float g. Now it's down to 8 errors.
 
Kathy Sigel
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what I actually have. Figured out how to copy. LOL.



[Moderator edit: added code tags]
 
Kathy Sigel
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a copy of my errors.

^
Student.java:29: error: illegal start of expression
public void setGpa(float g)
^
Student.java:29: error: ';' expected
public void setGpa(float g)
^
Student.java:29: error: ';' expected
public void setGpa(float g)
^
Student.java:37: error: ';' expected
public int getId()
^
Student.java:39: error: class, interface, or enum expected
return id;
^
Student.java:41: error: class, interface, or enum expected
public float getGpa()
^
Student.java:45: error: class, interface, or enum expected
public String toString()
^
8 errors
 
Junilu Lacar
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kathy,

Please UseCodeTags (←that's a link, click on it to learn how). As a one-time courtesy, I have added code tags for you.

You have braces that aren't properly matched. Again, it's actually before the spot that the compiler is reporting as having the error. Proper formatting and alignment of code really helps you find these kinds of errors. Format your code properly and you should be able to find the problems quickly. IDEs like Eclipse can format the code for you.

BTW, if you haven't been given the official welcome yet,

Welcome to the Ranch!

[ Edit: just noticed that Campbell already did the honors; never hurts to say it again though ]
 
Campbell Ritchie
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kathy Sigel wrote:Thanks for those replies. Sorry that I didn't add in the specifics. BTW, I did add a semicolon to the end of Student One. I just forgot to add it here.
. . .

Always copy and paste code. Otherwise we shall think that is what the compiler is noticing and miss the real error.

There are two common causes for class interface or enum expected compiler errors.
  • 1: Misspellings, e.g. Public class Foo. That produces an error message at the start of the file.
  • 2: Too many }s. That usually produces the error message near the end of the file.
  • I suggest you avoid IDEs at the beginner's stage, but get a decent text editor and write backwards. That looks strange but allows you to get all your indentation right first time.
     
    Kathy Sigel
    Greenhorn
    Posts: 8
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks for all of the input. I love this website. This is great!
    Can you also put "code tags" on your error messages as well?
     
    Kathy Sigel
    Greenhorn
    Posts: 8
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I had only tried to fix one of the curly braces instead of two. I kept coming up with the same errors. The mention helped me take a closer look. Now I'm down to 4 errors. Thanks again for the help.BTW, in our class we use jGrasp.
     
    Junilu Lacar
    Sheriff
    Posts: 17644
    300
    Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    You have a stray semicolon where there shouldn't be one. The rest of the errors are mismatched braces. Again, it helps to format and align your code properly. Adding spaces to have visual separation between methods helps improve readability. Look at a few Java Coding Style Guides available online, pick one that you like, and follow it. I'm partial to the Google style myself but usually follow the standard set by Sun/Oracle; both styles are in those search results, as well as JavaRanch's own style guide.
     
    Kathy Sigel
    Greenhorn
    Posts: 8
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks again folks! I fixed it. (Okay, LOL. We fixed it.)
     
    Junilu Lacar
    Sheriff
    Posts: 17644
    300
    Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    You're welcome.

    Just an observation on jGRASP: It might just be me but I don't think it's any more user-friendly than more established IDEs like Eclipse that have more features. I don't find the CSDs particularly useful either. Since it's what you use in class, I suppose you should still try to be familiar with it but I think a simpler text editor with code formatting capabilities would be better for beginners like you. Here's an article that has several suggestions: http://www.howtogeek.com/112385/the-best-free-text-editors-for-windows-and-linux/ for free programmer's editors.

    I use a Mac and have used TextWrangler and KomodoEdit. jEdit looks like it has some good features and it runs on multiple platforms. Notepad++ and Programmer's Notepad are good if you use Windows.
     
    Don't get me started about those stupid light bulbs.
    reply
      Bookmark Topic Watch Topic
    • New Topic