Mam kod, ktory powinien podawac 'login' skladajacy sie z 4 pierwszych znakow imienia i 3 pierwszych znakow numeru identyfikacyjnego (przy zalozeniu, ze jezeli ktores z pol nie spelnia warunkow, podawane jest cale bez ograniczen - np. imie mniejsze niz 4)
Konstruktor
public Student(String fullName, String studentID)
{
name = fullName;
id = studentID;
credits = 0;
}
Metoda dawania loginu
public String getLoginName()
{
String rvariable = null;
if (name.length() < 4)
{
if (id.length() < 3)
{
rvariable = name + id;
}
rvariable = name + id.substring(0,3);
}
else
{
rvariable = name.substring(0,4) + id.substring(0,3);
}
if (id.length() < 3)
{
if (name.length() < 4)
{
rvariable = name + id;
}
rvariable = name.substring(0,4) + id;
}
else
{
rvariable = name.substring(0,4) + id.substring(0,3);
}
return rvariable;
}
Jak podaje 'zle' dane to mowi ze nie da rady "java.lang.StringIndexOutOfBoundsException: String index out of range: 4"