How can we get SBJSON connectionDidFinishLoading method inside array data in another class?

Java inheritance problem still not working properly. The first part Animals compiles ,nothing else does.?

  • Here is the assignment :Lab #8, Objects, Inheritance and Polymorphism Purpose of Lab: Be able to: Write a Java program that defines, loads, and uses an array of objects. Create objects of classes. Understand the notion of polymorphism. Write superclasses and subclasses. Create objects of superclasses and subclasses. Instructions: 1. Write an Abstract Data Type called Animal. Include two instance variables in this class: a String for name and an integer for age. Write a constructor method that takes two arguments and a second constructor that takes no arguments. Write get and set methods for each of the two instance variables. Write a toString method which displays the values of the instance variables for any object of type Animal. Write a speak method that takes no arguments, returns nothing and displays “Arg! Arg!” on the monitor. 2. Write a second class called Duck, a subclass of class Animal. Add an additional instance variable to those inherited from Animal: an integer called feathers (this variable is used to store the number of feathers that a particular Duck object has). Write a constructor that takes three arguments and another constructor that takes no arguments. Provide set and get methods for the feathers instance variable. Override the toString method to display the values of all instance variables belonging to a Duck type of object. Override the speak method to display a value of “Quack! Quack!”. 3. Write a third class called Cow, also a subclass of class Animal. Add an additional instance variable to those inherited from Animal: an integer called spots (this variable is used to store the number of spots feathers that a particular Cow object has). Write a constructor that takes three arguments and another constructor that takes no arguments. Override the toString method to display the values of all instance variables belonging to a Cow type of object. Override the speak method to display a value of “Mooo! Mooo!”. 4. Finally, enter, compile and execute the Farm class shown below. Make sure that all of your classes (Animal, Duck, Cow and Farm) are in the same folder. Compile all of the classes. Run the Farm program. Answer the questions below. Here is my code so far: [CODE} public class Animals{ private String name; private int age; public Animals() { } public Animals( String nVal, int ageVal) { name =nVal; age = ageVal; } public void setN(String nVal) { name = nVal; } public String getN() { return name; } public void setA( int ageVal) { age = ageVal; } public int getA() { return age; } public String toString() { return "\nThe name is" + name +", and the age is" + age + "."; } } [CODE] [CODE] public class Duck extends Animals { private int feathers; public Duck() { super(); } public Duck(String nVal, int ageVal) { super(nVal,ageVal); feathers = feathersVal; } public void setFeathers(int feathersVal) { feathers= feathersVal; } public int getFeathers() { return feathers; } public String toString() { return "\nThe name is" + super.getN() + ", and the age is" + super.getA() + "\n The Duck's feathers are" +feathers+ "."; } } [CODE] [CODE] public class Cow extends Animals { private int spots; public Cow(int spots) { super(); } public Cow(String nVal, int spotsVal) { super(spots); spotsColor = spots; } public void setSpots(int spots) { spots= spotsColor; } public int getSpots(); } public String toString() { return "\nThe name is" +super.getN()+ ", and the age is" + super.getA() + "\n The Duck's feathers are" +feathers+ "\nThe Cow's spots are" +spots+"."; [CODE] [CODE] import javax.swing.JOptionPane.JOption; import javax.swing.*; public class Farm { public static void main( String[] args ); Animals[]farmAnimals = new Animals[4]; farmAnimals[0] = new Animals("Animals", 3); farmAnimals[1] = new Duck("Duck","green,grey feathers"); farmAnimals[2] = new Cow("Cow", 3, "brown white spots"); [CODE] any help greatly appreciated last assignment of the semester!

  • Answer:

    Hi, As per the question Duck needs 3 arguments in the constructor . You have given only two. In your code second argument of constructor is int. But in the main you call it with string ("green,grey feathers"). Types of arguments have to match. You have to make Animals an abstract class. If it is abstract ,you cannot make instance of it in main.ie farmAnimals[0] = new Animals("Animals", 3); will not work.

mr v at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

Hi there, From what I can see you're missing a small but important step outlined in the first few lines of your exercise: "Write an Abstract Data Type called Animal". I don't see the abstract keyword in your class definition, try adding this otherwise thats all I see wrong. Otherwise are there any specific errors/output that may help? Hope this helps.

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.