1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

compiling errors

Discussion in 'Software Development' started by new2java, Aug 17, 2007.

Thread Status:
Not open for further replies.
Advertisement
  1. new2java

    new2java Thread Starter

    Joined:
    Aug 17, 2007
    Messages:
    3
    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 .compareTo( Smallest ) < 0 );

    Smallest=array;


    }

    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());
    }

    }
     
  2. new2java

    new2java Thread Starter

    Joined:
    Aug 17, 2007
    Messages:
    3
    apparently I have bracket errors and need help fixing them
     
  3. new2java

    new2java Thread Starter

    Joined:
    Aug 17, 2007
    Messages:
    3
    so I have separated out things that were twisted up and this is hard to figure out...truly fristrated
     
  4. wookie2u

    wookie2u

    Joined:
    May 5, 2007
    Messages:
    21
    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.
     
  5. Chicon

    Chicon

    Joined:
    Jul 29, 2004
    Messages:
    6,650
    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:
    [SIZE=2]
    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);
        }
    }
    [/SIZE]
     
  6. wookie2u

    wookie2u

    Joined:
    May 5, 2007
    Messages:
    21
    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.
     
  7. Sponsor

As Seen On
As Seen On...

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.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/611268