Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 14 of 14

Thread: Need help, cannot find error

  1. #1
    Junior Member
    Join Date
    Dec 2009
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Need help, cannot find error

    Here is the code:

    import java.util.ArrayList;
    /**
     * A class to model an Analyser
     * 
     * @author (XXXX) 
     * @version (1.0)
     */
    public class Analyser
    {
        // instance variables - replace the example below with your own
        public ArrayList<Sample> samples;
     
        /**
         * Constructor for objects of class Analyser
         */
        public Analyser()
        {
            // initialise instance variables
           samples = new ArrayList<Sample>();
        }
     
        /**
         * An example of a method - replace this comment with your own
         */
        public void addSample(String location, int value)
        {
            if(value >= 0) {
                samples.add(new Sample(location, value));
            }
            else {
                System.out.println("The temperature is lower than absolute zero" + "\n" + "Temperature must be zero or greater");
            }
        }
     
        public void populate()
       {
           samples = new ArrayList<Sample>();
           samples.add(new Sample("Meston" + " " + 284));
           samples.add(new Sample("Fraser Noble" + " " + 274));
           samples.add(new Sample("Edward Wright" + " " + 309));
           samples.add(new Sample("New Kings" + " " + 260));
           samples.add(new Sample("Kings College" + " " + 265));
        }
     
        public void showSamples()
        {
            int index = 0;
            while(index < samples.size()) {
                System.out.println(samples.get(index));
                index++;
            }
        }
     
        public int highestTempRecorded()
        {
            int highest = 0;
            for(int index = 0; index < samples.size(); index++) {
                if(samples.get(index).getSampleValue() > highest)
                highest = samples.get(index).getSampleValue();
            }
            System.out.println("The highest temperature recorded is:" + " " + highest);
        }
     
        public void showFaultySensors()
        {
            int faultyLow = 260;
            int faultyHigh = 309;
            for(int index = 0; index < sample.size(); index++)
                if(samples.get.index().getSampleValue() < faultyLow) {
                    faultyLow = samples.get(index).getSampleValue();
                    System.out.println("Temperature is below normal:" + " " + faultyLow);
                }
                else if(samples.get.index().getSampleValue() > faultyHigh) {
                    faultyHigh = samples.get(index).getSampleValue();
                    System.out.println("Temperature is above normal:" + " " + faultyHigh);
                }
            }
        }

    Have problem with populate method. I am getting next mesage: cannot find symbol - constructor sample(java.lang.String)


    I have also another class called Sample:

    /**
     * Write a description of class Sample here.
     * 
     * @author (XXX) 
     * @version (1.0)
     */
    public class Sample
    {
        // representing location and values.
        private String location;
        private int value;
     
        /**
         * Constructor for objects of class Sample
         */
        public Sample(String location, int value)
        {
            this.location = location;
            this.value = value;
        }
     
        public String toString()
        {
            return "[" + location + "]" + " " + value;
        }
    }

    Where I am wrong?


  2. #2
    Junior Member
    Join Date
    Dec 2009
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default need help with my code

    Here is the code:


    import java.util.ArrayList;
    /**
     * A class to model an Analyser
     * 
     * @author (XXXX) 
     * @version (1.0)
     */
    public class Analyser
    {
        // instance variables - replace the example below with your own
        public ArrayList<Sample> samples;
     
        /**
         * Constructor for objects of class Analyser
         */
        public Analyser()
        {
            // initialise instance variables
           samples = new ArrayList<Sample>();
        }
     
        /**
         * An example of a method - replace this comment with your own
         */
        public void addSample(String location, int value)
        {
            if(value >= 0) {
                samples.add(new Sample(location, value));
            }
            else {
                System.out.println("The temperature is lower than absolute zero" + "\n" + "Temperature must be zero or greater");
            }
        }
     
        public void populate()
       {
           samples = new ArrayList<Sample>();
           samples.add(new Sample("Meston" + " " + 284));
           samples.add(new Sample("Fraser Noble" + " " + 274));
           samples.add(new Sample("Edward Wright" + " " + 309));
           samples.add(new Sample("New Kings" + " " + 260));
           samples.add(new Sample("Kings College" + " " + 265));
        }
     
        public void showSamples()
        {
            int index = 0;
            while(index < samples.size()) {
                System.out.println(samples.get(index));
                index++;
            }
        }
     
        public int highestTempRecorded()
        {
            int highest = 0;
            for(int index = 0; index < samples.size(); index++) {
                if(samples.get(index).getSampleValue() > highest)
                highest = samples.get(index).getSampleValue();
            }
            System.out.println("The highest temperature recorded is:" + " " + highest);
        }
     
        public void showFaultySensors()
        {
            int faultyLow = 260;
            int faultyHigh = 309;
            for(int index = 0; index < sample.size(); index++)
                if(samples.get.index().getSampleValue() < faultyLow) {
                    faultyLow = samples.get(index).getSampleValue();
                    System.out.println("Temperature is below normal:" + " " + faultyLow);
                }
                else if(samples.get.index().getSampleValue() > faultyHigh) {
                    faultyHigh = samples.get(index).getSampleValue();
                    System.out.println("Temperature is above normal:" + " " + faultyHigh);
                }
            }
        }
    Have problem with populate method. I am getting next mesage: cannot find symbol - constructor sample(java.lang.String)


    I have also another class called Sample:



    /**
     * Write a description of class Sample here.
     * 
     * @author (XXX) 
     * @version (1.0)
     */
    public class Sample
    {
        // representing location and values.
        private String location;
        private int value;
     
        /**
         * Constructor for objects of class Sample
         */
        public Sample(String location, int value)
        {
            this.location = location;
            this.value = value;
        }
     
        public String toString()
        {
            return "[" + location + "]" + " " + value;
        }
    }

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: need help with my code

    The code to create the Sample objects trying to use a constructor that accepts a single string, however the Sample class defines its constructor to accept a String and an int, perhaps you were trying to do the following:
    new Sample("Meston", 284)

  4. #4
    Junior Member
    Join Date
    Dec 2009
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: need help with my code

    solved, thanks!

    next error appearing here
     public int highestTempRecorded()
        {
            int highest = 0;
            for(int index = 0; index < samples.size(); index++) {
               [B] if(samples.get(index).getSampleValue() > highest)[/B]
                highest = samples.get(index).getSampleValue();
            }
            System.out.println("The highest temperature recorded is:" + " " + highest);
        }
    Last edited by helloworld922; December 5th, 2010 at 05:13 PM.

  5. #5
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: Need help, cannot find error

    I Think its this:

    samples.add(new Sample("Kings College" + " " + 265));
    You're treating the input as one String.

    try

    samples.add(new Sample("Kings College",265));

    that goes for all similar lines.

  6. The Following User Says Thank You to newbie For This Useful Post:

    Imeri0n (December 5th, 2010)

  7. #6
    Junior Member
    Join Date
    Dec 2009
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need help, cannot find error

    Thanks, this problem is solved!)

    I got next error here:

     public int highestTempRecorded()
        {
            int highest = 0;
            for(int index = 0; index < samples.size(); index++) {
                [B]if(samples.get(index).getSampleValue() > highest)[/B]
                highest = samples.get(index).getSampleValue();
            }
            System.out.println("The highest temperature recorded is:" + " " + highest);
        }

    Dunno what is wrong (

  8. #7
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: Need help, cannot find error

    Post your exception error message

  9. #8
    Junior Member
    Join Date
    Dec 2009
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need help, cannot find error

    cannot find symbol - method getSampleValue()

  10. #9
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: Need help, cannot find error

    you havent got a getSampleValue() method anywhere in your classes.

    Either create one or seek an alternative way of doing what you need.

  11. #10
    Junior Member
    Join Date
    Dec 2009
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need help, cannot find error

    made it like this:

    public int highestTempRecorded()
    {
    int highestTemp = samples[0];
    int highestTempRecorded = 0;
    for(int index = 1; index < samples.length; index++) {
    if(highestTempRecorded < samples[index]) {
    highestTempRecorded = samples[index];
    highestTempRecorded = index;
    }
    }
    }

    got such a message: array required, but java.util.ArrayList<Sample> found

  12. #11
    Junior Member
    Join Date
    Dec 2009
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need help, cannot find error

    Any ideas how to solve problem?

  13. #12
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: Need help, cannot find error

    Array[] and ArrayList are two different things

  14. #13
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: need help with my code

    Your Sample class doesn't have the method getSampleValue() (at least not as far as I can tell).

    You need to explicitly declare this method and define it.

  15. #14
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Need help, cannot find error

    In the future, please don't ask the same question in multiple topics. I've merged the two.

    Also, please use highlight or code tags with your code.

    [code]your code goes here[/code]
    looks like:
    //your code goes here

    [highlight=Java]//your code goes here[/highlight]

    looks like:
    //your code goes here

Similar Threads

  1. find LCS
    By Anemone_ in forum Algorithms & Recursion
    Replies: 1
    Last Post: November 28th, 2010, 02:03 PM
  2. Can't Find Problem
    By aussiemcgr in forum What's Wrong With My Code?
    Replies: 7
    Last Post: August 15th, 2010, 09:42 AM
  3. cannot find symbol Error
    By bananasplitkids in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 9th, 2010, 02:36 AM
  4. where can i find the tmp/foo directory?
    By Idy in forum Java IDEs
    Replies: 11
    Last Post: January 19th, 2010, 11:21 AM
  5. Replies: 2
    Last Post: November 3rd, 2009, 06:28 AM