I was working on a program for my college class. I was given two sample files (a class and an interface), which I was told specifically by the instructor not to modify. The issue is that there is an error at runtime (that does not show in my IDE) from the java class im not supposed to modify when I run the program:
(this error repeats for dog, cat, cow)
here is the code for the class and the interface:
// Student must not modify the code in this file. //
class Proj12{
public static void main(String[] args){
System.out.println(""+
"Your instructor will rearrange then"+
"order of some of the following statementsn"+
"when your assignment is graded.n");
Proj12Runner var = new Proj12Runner();
System.out.println("=====This line is required=====");
Animal cat = new Cat();
Animal dog = new Dog();
Animal cow = new Cow();
System.out.println("=====This line is required=====");
System.out.println(cat.speak());
System.out.println(dog.speak());
System.out.println(cow.speak());
System.out.println("=====This line is required=====");
System.out.println(dog.run());
System.out.println("=====This line is required=====");
cat.sleep("cat");
dog.sleep("dog");
cow.sleep("cow");
}//end main
}//end class Proj12
//===============================================//
this is the code for the interface I am not supposed to modify:
interface Animal{
public String speak();
public void sleep(String data);
public int run();
}//end interface
here are the classes that I made (all in seperate files) that I am permitted to edit:
public class Proj12Runner {
public Proj12Runner(){
System.out.println("I certify that this program is my own workn" +
"and is not the work of others. I agree notn" +
"to share my solution with others.n" +
"(my name");
}
}
public class Dog implements Animal{
public String speak(){
return ("I am a dogn " +
"My name is Fido");
};
public void sleep(String data){
System.out.println(data + ":Snooze - ");
};
public int run(){
System.out.println("Fido: ");
return 1024;
};
}
public class Cat implements Animal{
public String speak(){
return ("I am a catn " +
"My name is Cleo");
};
public void sleep(String data){
System.out.println(data + ":Snore - ");
};
public int run(){
return 0;
};
}
public class Cow implements Animal{
public String speak(){
return ("I am a cown " +
"My name is Bessie");
};
public void sleep(String data){
System.out.println(data + ":Yawn");
};
public int run(){
return 0;
};
}
All of the classes are in the same directory.
(intfc.java is the name of the .java file with the “Animal” interface in it)
I am pretty sure the issue has to do with the fact that objects cannot be created from interfaces, at least according to any online help I was able to find, but of course I am not permitted to edit that part of the code! ( 😀 )
i would appreciate any help with this issue!