Here is my RandomSequence class code: import java.util.*;
public class RandomSequence implements Sequence
{
private ArrayList<Double> random;
public RandomSequence()
{
random = new ArrayList<Double>();
}
public List<Double> firstTenTerms()
{
if(random.size()!=0)
{
while(random.size()>0)
{
random.remove(random.size()-1);
}
}
for(int k=0; k<10; k++)
{
random.add((int)(Math.random()*10)+1.0);
}
return random;
}
}
And this is my driver class: import java.io.; import java.util.;
public class SequenceMain
{
public static void main(String[] args) throws Exception
{
File f = new File("sequence1.txt");
Scanner scan = new Scanner(f);
System.out.println("I'm going to generate a random \"sequence\" and sort it. Here're the first 10 terms of sequence.");
System.out.println(RandomSequence.firstTenTerms());
}
public void ascendingSort(List<Double> alist)
{
Collections.sort(alist);
}
}
When I run the driver class, I keep on getting these error messages:
SequenceMain.java:13: error: non-static method firstTenTerms() cannot be referenced from a static context
System.out.println(RandomSequence.firstTenTerms());
SequenceMain.java:18: error: non-static method ascendingSort(List<Double>) cannot be referenced from a static context
ascendingSort(alist);
There already seems to be quite a few questions related to the non-static methods and static context etc, and I've gone through some of those posts, but frankly, I'm now more confused than before.
Update: Thank you for those who gave me feedback on line 13, but how can I fix 18? I feel that it's a bit different.