Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Software Development Software Development
Search Search
Search for:
Tech Support Guy > > >

compiling errors


(!)

new2java's Avatar
new2java new2java is offline
Junior Member with 3 posts.
THREAD STARTER
 
Join Date: Aug 2007
Experience: Beginner
17-Aug-2007, 12:54 PM #1
compiling errors
I have several errors when I try to build this and don't have too much experience fixing them please give me some guidance.

import java.util.*;

public class UMUC_Comparable {

public static void main(String[] args) {

Student[] studentArray = { new Student("Tom", 87),
new Student("Cindy", 100),
new Student("Pat", 75),
new Student("Anne", 92),
new Student("Matt", 82)};

Student smallestStudent;
int value = 100;
int found = 0;
int index = 0;

for(Student t : studentArray) {

if(t.getAverage() < value) {
value = t.getAverage();
found = index;
}
++index;
}

System.out.println("Smallest student = "
+ studentArray[found].getName()
+ " average = "
+ studentArray[found].getAverage());

}
}

class Student extends UMUC_Comparable {
private int average;
private String name;

public Student (String name, int average) {
this.average = average;
this.name = name;
}

public String getName() {
return name;
}

public int getAverage() {
return average;
}

public int compareTo(Student ) {
}
return (this.average - s.average);
}



}//CRR end findSmallest



static UMUC_Comparable findSmallest (UMUC_Comparable[] array )
{
UMUC_Comparable Smallest = array[0];

for (int i=1; i<array.length; ++i){
}

if (array [i].compareTo( Smallest ) < 0 );

Smallest=array[i];


}

return Smallest;
}//end

public static void main ( String[] args)
{
int studentArray1 [] = {0 , 1, 2, 3, 4};

Student studentArray[] = { new Student("Tom", 87),

new Student("Cindy", 100),
new Student("Pat", 75),
new Student("Anne", 92),
new Student("Matt", 82)};
//end function

for (int i = 0; i < studentArray.length; i++) {
//end for loop

System.out.println( "The smallest int is: " + findSmallest (studentArray1));

System.out.println ("smallest student is: " +
( (Student) findSmallest ( studentArray ) ).getName());
}

}
new2java's Avatar
new2java new2java is offline
Junior Member with 3 posts.
THREAD STARTER
 
Join Date: Aug 2007
Experience: Beginner
17-Aug-2007, 01:40 PM #2
apparently I have bracket errors and need help fixing them
new2java's Avatar
new2java new2java is offline
Junior Member with 3 posts.
THREAD STARTER
 
Join Date: Aug 2007
Experience: Beginner
17-Aug-2007, 02:06 PM #3
so I have separated out things that were twisted up and this is hard to figure out...truly fristrated
wookie2u's Avatar
wookie2u wookie2u is offline
Computer Specs
Junior Member with 21 posts.
 
Join Date: May 2007
Location: Brisbane
Experience: Intermediate
17-Aug-2007, 09:22 PM #4
Notepad sux!
newbie,

> truly fristrated

You should patent that saying, and I think I know how you feel.

Which program editor are you using? Does it have "bracket matching". if not google for "free programmers editor" (or just look at http://en.wikipedia.org/wiki/List_of_text_editors) and take your pick.

I recommend edit plus, but it's NOT free.

I've also used ConTEXT and jEdit, which are both free, and are both pretty good.

A decent programmers editor assists you with matching up your 'quotes', "double-quotes", (brackets), /*comments*/, and {braces}.

I'd recommend that you steer clear of IDE's until you _need_ a debugger, and not just to play with. They're complex beasts in there own right, and (IMHO) detract and distract from the business at hand... which is learning the java language, it's core API's, and OO design.

keith.
Chicon's Avatar
Chicon Chicon is offline   Chicon has a birthday soon!
Computer Specs
Member with 6,650 posts.
 
Join Date: Jul 2004
Location: 50 34' 07.13" N - 04 10' 23.
Experience: Second socks retriever
18-Aug-2007, 12:52 AM #5
Hi new2java,

wookie2u is right : you need a good IDE as it will help you to spot on the fly syntax errors.

Also, I've had a look to your coding : there's no need to make the class Student inherit from the class UMUC_Comparable (extends).
I've simplified your program this way :
Code:

public class UMUC_Comparable {
    
    public static void main(String[] args) {
        
        Student[] studentArray = { new Student("Tom", 87),
        new Student("Cindy", 100),
        new Student("Pat", 75),
        new Student("Anne", 92),
        new Student("Matt", 82)};
        
        Student s = findSmallest(studentArray);
        System.out.println("Name : " + s.getName() + " / Average : " + s.getAverage());
    }
    
    public static Student findSmallest(Student[] array) {
        Student smallest = array[0];
        for (int i=1; i < array.length; i++ ) {
            if (array[i].compareTo(smallest) < 0) {
                smallest = array[i];
            }
        }
        return smallest;
    }
}

class Student {
    private int average;
    private String name;
    
    public Student(String name, int average) {
        this.average = average;
        this.name = name;
    }
    
    public String getName() {
        return name;
    }
    
    public int getAverage() {
        return average;
    }
    
    public int compareTo(Student s) {
        
        return (this.average - s.average);
    }
}
wookie2u's Avatar
wookie2u wookie2u is offline
Computer Specs
Junior Member with 21 posts.
 
Join Date: May 2007
Location: Brisbane
Experience: Intermediate
18-Aug-2007, 01:55 AM #6
chicon,

> wookie2u is right : you need a good IDE
That's not exactly what I said. In fact I'm of the oh so humble opinion (no sarcasm scarring my soul) that the last thing a newbie should have is a fancy IDE, coz they're a big DISTRACTION from the job at hand.

Nice job on KISSing that code though.

cheers. keith.
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
WELCOME TO TECH SUPPORT GUY!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.


(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑

Content Relevant URLs by vBSEO 3.3.2