I have a java program that is due tomorrow and I cant get itto work because it d
ID: 3617370 • Letter: I
Question
I have a java program that is due tomorrow and I cant get itto work because it doesn't have a main method. Please help me. Hereis the program: class Animal {private String type;
public Animal (Stringtype){
this.type =type;
}
public String getAnimalName(){
Stringst = "This is a";
return (st +type);
}
}
I have a java program that is due tomorrow and I cant get itto work because it doesn't have a main method. Please help me. Hereis the program: class Animal {
private String type;
public Animal (Stringtype){
this.type =type;
}
public String getAnimalName(){
Stringst = "This is a";
return (st +type);
}
}
Explanation / Answer
import java.util.Scanner; public class Animal { private String type; public Animal (String type){ this.type =type; } public String getAnimalName(){ String st = "This is a"; return (st + type); } public static void main(String[] args) { //making object of scanner class for takinginput Scanner input = newScanner(System.in); //taking input from user and save in Stringobject String yourAnimalName=input.nextLine(); //Making Object of Animal Class Animal yourAnimal = newAnimal(yourAnimalName); //printing Animal name by callinggetAnimalName() System.out.println(yourAnimal.getAnimalName()); } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.