0
I have 2 classes that work well independently of each other. I joined the 2 in one and got 3 build errors, the error message says:
ilegal static declaration.
how to solve error on lines 42, 58 6 69.
The code to follow:
import java.util.*;
public class nesTudo
{
class UserInfo
{
String user; String pass; String secretCode;
ArrayList <UserInfo> InfoList = new ArrayList<UserInfo> ();
public void userInternalDatabase (UserInfo info)
{
this.user = info.user;
this.pass = info.pass;
this.secretCode = info.secretCode;
}
public void addUser(String i, String j, String k)
{
UserInfo newUser = new UserInfo();
newUser.user = i;
newUser.pass = j;
newUser.secretCode = k;
InfoList.add(newUser);
}
public Object findUsername(String a)
{
for (int i=0; i <InfoList.size(); i++)
{
if (InfoList.get(i).user.equals(a))
{
return "This user already exists in our database.";
}
}
return "NÃO EXISTE ESSE UTILIZADOR.";
}
}
class DadosGuardados
{
private static int lerNumero(Scanner kb, String mensagem, String mensagemErro)
{
while (true)
{
System.out.println(mensagem);
try
{
return Integer.parseInt(kb.nextLine());
}
catch (NumberFormatException e)
{
System.out.println(mensagemErro);
}
}
}
private static boolean lerSimNao(Scanner kb, String mensagem, String mensagemErro)
{
while (true)
{
System.out.println(mensagem);
String x = kb.nextLine();
if (x.equalsIgnoreCase("S")) return true;
if (x.equalsIgnoreCase("N")) return false;
System.out.println(mensagemErro);
}
}
public static void main(String[] args)
{
Scanner kb = new Scanner(System.in);
System.out.println("Bem-vindo, utilizador.");
boolean maisRecarga = true;
while (maisRecarga)
{
int recarga = lerNumero(kb, "Introduza o número da recarga: ", "Isso que você digitou não era um número. Por favor, tente novamente.");
System.out.println("Você digitou " + recarga + ".");
maisRecarga = lerSimNao(kb, "Tem mais recarga para registar?\nResponda `S´ para continuar ou `N´ para terminar: ", "Era para você responder S ou N! Por favor, tente novamente.");
}
System.out.println("Obrigado, até o próximo registro.");
}
}
}
We do not have the numbers, have to inform which are the lines. but already put forward that should be to take the
static
how the error is reporting on them. The problem may be further down. (Putting things together) programming is not usually just copying and pasting codes without understanding what they do. A class that hasTudo
in the name seems suspicious tb. The code seems very confusing.– Maniero
@bigown mentioned lines 42, 58 and 69.
– cambine
Where? I don’t see it. There’s only numbers that mean nothing to us.
– Maniero
@bigown I accept that the comic is confusing except to be guessed.
– cambine
So it’s proven to be a class that does more than it should even :P
– Maniero