import java.io.*;
class Main0
{
public static void main(String args[])
{
String onoma, epitheto, key01;
short AriMit, EtosEis, AM, key02;
int i, pos;
Foititis pinakas[] = new Foititis(3);
for (i = 0; i < pinakas.length; i++)
{
System.out.println("Ola ta stoixeia na einai taksinomimena symfwna me ton Arithmo Mitroou." + "\n" + "Dwste Onoma.");
do
{
onoma = FUserInput.getString();
if (onoma == "x")
System.out.println("Mh egkyrh timh. Epanalagete");
} while (onoma == "x");
System.out.println("Dwste Epitheto.");
do
{
epitheto = FUserInput.getString();
if (epitheto == "x")
System.out.println("Mh egkyrh timh. Epanalagete");
} while (epitheto == "x");
System.out.println("Dwste Arithmo Mitrwou.");
do
{
AriMit = FUserInput.getshort();
if (AriMit == -1)
System.out.println("Mh egkyrh timh. Epanalagete");
} while (AriMit == -1);
System.out.println("Dwste Etos Eisagwghs.");
do
{
EtosEis = FUserInput.getshort();
if (EtosEis == -1)
System.out.println("Mh egkyrh timh. Epanalagete");
} while (EtosEis == -1);
pinakas[i] = new Foititis(onoma, epitheto, AriMit, EtosEis);
}
pos = 1;
System.out.println(Foititis.toString(pos, pinakas));
}
}
class Foititis
{
private String onoma, epitheto;
private short AriMit, EtosEis;
public Foititis (String on, String ep, short AM, short EE)
{
onoma = on;
epitheto = ep;
AriMit = AM;
EtosEis = EE;
}
public String getEpwnymo() //alles klaseis
{
return epitheto;
}
public String toString(int j, Foititis b[])
{
String emf;
emf = b[j].onoma;
}
}
class FUserInput
/*dedomenwn kateli3a na xrisimopoihsw thn "FUserInput" gia ola ta dedomena, anti na kanw "catch" to "exception" gia kathe scanner ksexwrista, kathws eixa skopo na xrisimopoihsw mono scanner)*/
{
static String getString()
{
String line;
InputStreamReader eisodosDouble = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(eisodosDouble);
try
{
line = br.readLine();
return line;
}
catch(Exception e)
{
return "x";
}
}
static short getshort()
{
String line;
InputStreamReader eisodosDouble = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(eisodosDouble);
try
{
line = br.readLine();
short i = Short.parseShort(line);
return i;
}
catch(Exception e)
{
return -1;
}
}
}
This is not a duplicate of anything, I am not asking about my string equations but about the toString method that I want to use!!!!
So I have this code... all it does is to create an array of objects of type Foititis
, named pinakas
and having the four attributes. If you look at class named Foititis
you will notice a toString
method, all I want to do is to use the toString
method to show something on the screen (at this example it is simplified to the onoma
attribute of the array-object). Note that I also want to send the certain position of the array that I want to be seen(pos -> j), at this example the position is fixed (set to 1) but in the actual code it won't.
I try to compile it and I get these 2 errors, the second one is probably justified because I haven't written the code in the proper way, but what about the first? I have done the same thing again and I had no problem (at creating an array of objects).