Моя проблема> У toString есть ошибка, говорящая, что я havent добавил return;toString не работает в моем классе
Что я сделал, я сделал класс, который генерирует либо случайное везение или случайное время
public randomLuckOrTime(){
Random rand = new Random();
int t = rand.nextInt(2);
if(t == 0){
randomTime();
}
else if(t == 1){
randomLuck();
}
}
двух классов
public Luck randomLuck(){
int [] num = {1,2,3,4,5,6,7,8,9,10,5,6,6,9,17};
Luck q = new Luck();
Random rand = new Random();
int Rand = rand.nextInt(15);
q.setLuck(num[Rand]);
this.numbr = q.getLuck();
return q;
}
public Time randomTime(){
int [] TImeList = {10,20,30,40,50};
Time l = new Time();
Random rand = new Random();
int Rand = rand.nextInt(5);
l.setTime(TimeList[Rand]);
this.Time = l.getTime();
return l;
}
мой ToString, который я хочу меняться в зависимости от вариант двух печатается.
public String toString(){
if(this.Time == 0){
String s = " " +"\n";
s += "Random Number: " + this.numbr+ "\n";
return s;
}
else if(this.numbr = 0){
String s = " " +"\n";
s += "Random Time: " + this.Time+ "\n";
return s;
}
}
Это очень понравилось :) –