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?