Results 1 to 3 of 3
- 12-15-2012, 01:19 AM #1
Member
- Join Date
- Dec 2012
- Posts
- 1
- Rep Power
- 0
Complete newbie to Java, can't do my homework
As for the text of my homework (I study, besides other things, software development. We've started with functional programming and haskell and now moved to OOP and Java), I must implement a class and some functions. Seems for me that I have did everything right (or near it), but the compiler says I'm wrong. Here's the code:
As an error, compiler gives me "class, interface, or enum expected" many times.Java Code:class List { double[] content; } List create (){ return new List; } void append (List l, double elem){ l[l.length+1] = elem; } int size ( List l ){ return l.length; } double get ( List l, int index ){ return l[index]; } void put (List l, int index){ l[index] = elem; } void remove ( List l, int index ){ for ( int i = index; i < l.length-1; i++ ) l[i] = l[i+1]; l[l.length-1] = null; } boolean contains ( List l, double elem){ for ( int i = 0; i<l.length-1; i++ ) { if ( l[i] == elem ) return True; } return False; } public class ListsManipulation { public static void main( String[] args) {} }
That's the complete listing:
I don't know what the compiler likes not...Roman-Reimche-2:Uebungen rreimche$ javac u9.java
u9.java:6: class, interface, or enum expected
List create (){ return new List; }
^
u9.java:6: class, interface, or enum expected
List create (){ return new List; }
^
u9.java:8: class, interface, or enum expected
void append (List l, double elem){ l[l.length+1] = elem; }
^
u9.java:10: class, interface, or enum expected
int size ( List l ){ return l.length; }
^
u9.java:12: class, interface, or enum expected
double get ( List l, int index ){ return l[index]; }
^
u9.java:16: class, interface, or enum expected
}
^
u9.java:19: class, interface, or enum expected
for ( int i = index; i < l.length-1; i++ )
^
u9.java:19: class, interface, or enum expected
for ( int i = index; i < l.length-1; i++ )
^
u9.java:21: class, interface, or enum expected
l[l.length-1] = null;
^
u9.java:22: class, interface, or enum expected
}
^
u9.java:25: class, interface, or enum expected
for ( int i = 0; i<l.length-1; i++ )
^
u9.java:25: class, interface, or enum expected
for ( int i = 0; i<l.length-1; i++ )
^
u9.java:26: class, interface, or enum expected
{ if ( l[i] == elem ) return True; }
^
u9.java:28: class, interface, or enum expected
}
^
14 errors
- 12-15-2012, 01:31 AM #2
Re: Complete newbie to Java, can't do my homework
Please go through the Forum Rules -- particularly the third paragraph.
Also learn and respect the Java coding conventions in respect of line breaks and indents: Code Conventions for the Java Programming Language: Contents
You need to start at the beginning. Methods have to be inside a class.
Lesson: The "Hello World!" Application (The Java™ Tutorials > Getting Started)
Trail: Learning the Java Language (The Java™ Tutorials)
dbWhy do they call it rush hour when nothing moves? - Robin Williams
-
Re: Complete newbie to Java, can't do my homework
The compiler is right 99.9% of the time, and it is right this time. Check all of your opening and closing curly braces, especially the braces that enclose the whole class. Notice anything off?
Similar Threads
-
Complete newbie
By diegoigaete in forum New To JavaReplies: 6Last Post: 04-20-2012, 12:18 PM -
Steps to create web app for complete newbie
By motorola in forum JavaServer Pages (JSP) and JSTLReplies: 5Last Post: 10-16-2011, 11:56 AM -
can anyone help me,a complete newbie?
By keye906 in forum New To JavaReplies: 13Last Post: 06-02-2010, 01:56 PM -
Complete Java Removal
By jpChris in forum New To JavaReplies: 14Last Post: 05-25-2010, 12:46 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks