I made a class that returns 3 values of an arraylist to the main program but when I use my get()
method the compiler throws me en error that cant find this method - symbol. I tried the same thing doing it with not an arraylist but with an array and it seems to work. But I cant figure the way it will be with an Array List.
//Error is on "action evt" show button on second mark of code.
Error msg is: "Cannot find symbol-method getmarka()".
I am posting the code below maybe you can help me.
The Class with get method that returns the values:
public class Cars
{
private String modelo,marka;
private int kyvismos;
public Cars(String m,String ma,int k)
{
modelo=m;
marka=ma;
kyvismos=k;
}
public String getmodelo()
{
return modelo;
}
public String getmarka()
{
return marka;
}
public int getkyvismos()
{
return kyvismos;
}
public void setmodelo(String m)
{
modelo=m;
}
public void setmarka(String ma)
{
marka=ma;
}
public void setkyvismos(int k)
{
kyvismos=k;
}
public String toString()
{
return modelo+","+marka+","+kyvismos;
}
}
Here is the Class that gets the category-class on top.
public class MyFrame extends Frame
{
ArrayList<Cars> Cars = new ArrayList<>();
private Button add;
private Button show;
private Button quit;
public MyFrame(String title)
{
super(title);
resize(500,300);
setResizable(false);
setLayout(new GridLayout(3,1));
add=new Button("ADD");
show=new Button("SHOW");
quit=new Button("QUIT");
add (add);
add (show);
add (quit);
}
public boolean action(Event evt,Object arg)
{
if(evt.target.equals(add))
{
String value1= JOptionPane.showInputDialog("Enter Car Model ");
String value2= JOptionPane.showInputDialog("Enter Car Mark ");
int value3= Integer.parseInt(JOptionPane.showInputDialog("Enter Kyvismos "));
Integer I=new Integer(value3);
Cars.add(new Cars(value1,value2,value3));//or pinakas.add(value);
}
else
if(evt.target.equals(show))
{
String s="";
int i;
for(i=0;i<Cars.size();i++){
**//here is the error on Cars.getkyvismos() or getmarka() or getmodelo();**
//if(Cars.getkyvismos()>1900)
s=s+Cars.getmarka()+Cars.getmodelo()+"\n";
}
JOptionPane.showMessageDialog(null, "cars with kyvismo >1900 are \n " + s);
}
else
if(evt.target.equals(quit))
{
System.exit(0);
}
return true;
}
}
Thanks in advance and sorry if its a newbie question!