Zookal
Zookal

We’d love to hear any feedback or comment from you!

© 2011-2021 Zookal Pty Ltd

View question and answer

From our collection of questions and answers
Engineering · Computer Science
Question details


Below is the JAVA question:
Working alone or with a partner: and then using what you have learned about polymorphism, inheritance, and interfaces Copy the brown code below into a file. Save it. Then write the 4 classes and 1 interface that are required to make the code below work to have the blue output show below. (Make sure to read the note at the bottom for full credit.) public class CS145Chapter9Inclass public static void main (String[] args) Animal[] pets new Animal[6]; pets[0] new Dog(Fred); pets[1] new Dog(Ben); pets [2]new Cat(Sue); pets[3]new Cat(Julie); pets[4] = new Kitten(Maria); pets[5]new Puppy(Lee); for(int i-0; i < pets.length; i++) System.out.print (pets[i]); System.out.println( says pets[i].makeSound() );The Final Output should look like the following: Fred the dog says Woof Ben the dog says Woof Sue the cat says Purr Julie the cat says Purr Maria the kitten says Purr Lee the puppy says Woof In order to get full credit however, you need to limit yourself to a total of 2 fields total in all of yo asses and maintain proper encapsulation of all classes Note that this means 2 fields in total, NOT 2 fields per class.

Below is my code

public interface Animal public String makeSound);

public class Cat implements Animal { private String name; public Cat(String name)( this.name-name; public String getName( return name; public String makeSoundc)( return Purr public String to tring(O return name+ the Cat ;public Kitten extends Cat public toString Stringf return super.getName+ the kitten ;
public class Dog implements Animalf private String animalName; public Dog(String animalName) this.animalName-animalName; public String makeSoundc) returnWoof; public String getName(Ot return animalName; public String toString(O return animalNamet the dog;public Puppy extends Dog public Puppy (String name) super(name); public String toString(O return super.getName()+ the puppy;


the error is , please explain it with details. Thanks!:
jGRASP exec: javac -g Kitten.java Kitten.java:1: error: class, interface, or enum expected public Kitten extends Cat Kitten.java:3: error: class, interface, or enum expected public toString Stringf Kitten.java:5: error: class, interface, or enum expected 3 errors jGRASP wedge2: exit code for process is 1. jGRASP: operation complete.Puppy. java:1: error: class, interface, or enum expected public Puppy extends Dogí Puppy.java:3: error: class, interface, or enum expected public Puppy (String name) Puppy-java:5: error: class, interface, or enum expected Puppy.java : 8: error : class, interface, or enum expected public string tostring)( Puppy-java:10: error: class, interface, or enum expected 5 errors

Answer
Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.

Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.Find step-by-step answers from expert tutors to questions asked by students like you. Start 14-day free trial.