사용자에게 애완 동물 이름, 종족, 갈증 수준을 알려주고 이에 따라 응답을 제공하는 프로그램을 작성하려고합니다.자바는 하나의 메서드에서 여러 문자열을 반환합니다.
누군가가 나를 메신저로 데려다 줄 수 있다면 감사하겠습니다. askpetname과 thirstlevel의 두 가지 메소드에는 전역 변수를 사용하지 않고 전체 클래스에서 액세스 할 수있는 2 개의 문자열이 있습니다.
누군가가 내가 무엇을 잘못하고 있는지 또는 올바른 방향으로 나를 가리키고 있는지 말해 줄 수 있습니까?
또한 지루한 작업을위한 메서드를 과도하게 사용하는 것은 좋지 않지만 구문을 암기하는 데 도움이된다는 것을 알고 있습니다.
감사합니다.
class dinoo
{
public static void main(String[] p)
{
explain();
output();
System.exit(0);
}
public static void explain()
{
print("The following program demonstrates use of user input by asking for pet name.");
return;
}
public static String askpetname()
{
Scanner scanner = new Scanner(System.in);
print("Name your dinosaur pet!");
String petname = scanner.nextLine();
print("Awesome, cool dinosaur name, what species is " + petname+ " ?");
String petspecies = scanner.nextLine();
return petname, petspecies;
}
public static int thirstlevel()
{
Random ran = new Random();
int thirst = ran.nextInt(11);
int hunger = ran.nextInt(11);
return thirst,hunger;
}
public static String anger(int thirst, int hunger)
{
double angerscore = (thirst+hunger)/2;
String temper;
if(angerscore<=2)
{
temper = "Serene";
}
else if(3<=angerscore<=6)
{
temper= "Grouchy";
}
else if(6<angerscore)
{
temper = "DANGEROUS";
}
return temper;
}
public static String warning()
{
if (temper.equals("Serene"))
{
print("He's looking happy!");
}
else if(temper.equals("Grouchy"))
{
print("Ahhh hes a bit "+temper+", you better start feeding him before he gets mad!");
}
else if(temper.equals("DANGEROUS"))
{
print("GET OUT OF THERE, HES " + temper+"!!!. He will have to be put down for everyones safety.");
}
}
public static void output()
{
print(askpetname() + "'s, thirst level is "+thirstlevel()+"/10");
return;
}
public static String print(String message)
{
System.out.println(message);
return message;
}
}
어떤 문자열에 대해 이야기 할 수 있습니까? 'thirstlevel()'을 보면 문자열이 없습니다. 이 문자열을 어디에서 사용 하시겠습니까? 글로벌 변수는 세계에서 최악의 것은 아닙니다. – user123
내 나쁜 나는 thirstlevel에 int 의미. – coding95