I am attempting to get a program to organize restaurant ratings and such, but cannot find the symbol error listed in my second program. I think it's a declaration problem, but I'm struggling to find a solution. Below are the two programs. The error JGrasp is giving me is in line 7 of the second section of code which involves Array List.
import java.util.*;
class restaurant
{
int[][] ratings;
int row;
int col;
restaurant(int n,int y)
{
row=n;
col=y;
ratings=new int[n][y];
Random ran=new Random();
for(int i=0;i<n;i++)
{
for(int j=0;j<y;j++)
{
ratings[i][j]=ran.nextInt(1,6);
}
}
}
public void printratings()
{
System.out.println("Ratings of the restaurants over the years: Row: restaurants Column: Years");
for(int i=0;i<row;i++)
{
System.out.print("restaurant "+(i+1)+": ");
for(int j=0;j<col;j++)
{
System.out.print(ratings[i][j]+" ");
}
System.out.println();
}
}
public ArrayList<Integer> func()
{
ArrayList<Integer> temp=new ArrayList<Integer>();
for(int i=0;i<row;i++)
{
boolean flag=false;
for(int j=0;j<col;j++)
{
if(ratings[i][j]==5)
{
flag=true;
break;
}
}
if(flag==true)
{
temp.add(i);
}
}
return temp;
}
public ArrayList<Double> average()
{
ArrayList<Double> temp=new ArrayList<Double>();
for(int i=0;i<row;i++)
{
double total=0;
for(int j=0;j<col;j++)
{
total+=ratings[i][j];
}
total/=col;
temp.add(total);
}
return temp;
}
public void printstar()
{
for(int i=0;i<row;i++)
{
boolean flag=true;
for(int j=0;j<col;j++)
{
if(ratings[i][j]<5)
{
flag=false;
break;
}
}
if(flag==true)
{
System.out.print(i+" ");
}
}
}
public boolean stars()
{
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
if(ratings[i][j]==5)return true;
}
}
return false;
}
}
**Second Section of code starts here**
public class client
{
public static void main(String[] args)
{
restaurant h=new restaurant(4,10);
h.printratings();
ArrayList<Double> temp=h.average(); **This line is my problem**
System.out.println("Average Rating of all the restaurants: ");
for(int i=0;i<temp.size();i++)
{
System.out.println("restaurant "+(i+1)+":"+" "+temp.get(i));
}
}
}