6 Replies - 1000 Views - Last Post: 07 November 2011 - 07:10 AM Rate Topic: -----

#1 nielatjie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 28-August 11

using abstract classes and methods compiling error

Posted 06 November 2011 - 09:49 AM

Hey guys me again :helpsmilie:

Ive finished my coding but they give me an error!

I had to create 3 classes and the one they give me

public abstract class Animal
{
	String type;

	public Animal(String type)
	{
		this.type = type;
	}

	public abstract void describe();
	public abstract void sound();
	public abstract void sleep();
	public abstract void move();
}


public abstract class Bird extends Animal
{
	protected String breed;

	public Bird(String name, String breed)
	{
		super("Bird");
		this.breed = breed;
	}

	public void move()
	{
		System.out.println("This " +breed+ " flies up and away!");
	}
}


public class Cat extends Animal
{
	private String name;
	protected String breed;

	public Cat(String name)
	{
		super("Cat");
		this.name = name;
	}

	public Cat(String name, String breed)
	{
		super("Cat");
		this.name = name;
		this.breed = breed;
	}

	public void describe()
	{
		System.out.println(name + ", a breed of " +type+ " called " + breed);
	}

	public void sound()
	{
		System.out.println("Meow");
	}

	public void sleep()
	{
		System.out.println(name+ " is having purrfect dreams!");
	}

	public void move()
	{
		System.out.println("This little kitty moves fast!");
	}

	public String getName()
	{
		return name;
	}
}


public class Robin extends Bird
{
	private String name;

	public Robin(String name)
	{
		super("Robin");
		this.name = name;
	}

	public void describe()
	{
		System.out.println(name + ", a breed of " +type+ " called" + breed);
	}

	public void sound()
	{
		System.out.println("Tweet Tweet!");
	}

	public void sleep()
	{
		System.out.println(name + " the " +breed+ "sleeps with one eye open for the cat!");
	}

	public String getName()
	{
		return name;
	}
}


This source code they gave me

public class AbstractTest
{
	public static void main(String[] args)
	{
		Cat cat = new Cat("Kitty", "Angora");
		Robin bird = new Robin("Rockin");

		System.out.println("For the cat: ");
		System.out.print("This is:       "); cat.describe();
		System.out.print("Sound:         "); cat.sound();
		System.out.print("Sleeping       "); cat.sleep();
		System.out.print("Moving         "); cat.move();
		System.out.println("\n");

		System.out.println("For the Robin: ");
		System.out.print("This is:         "); bird.describe();
		System.out.print("Sound:           "); bird.sound();
		System.out.print("Sleeping:        "); bird.sleep();
		System.out.print("Moving:          "); bird.move();
		System.out.println("\n");

		System.out.println("\nEnd of program.");
	}
}


Error:

cannot find symbol
symbol: constructor Bird(java.lang.String)
location: class Bird
super("Bird");

Please help

Is This A Good Question/Topic? 0
  • +

Replies To: using abstract classes and methods compiling error

#2 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2831
  • View blog
  • Posts: 11,986
  • Joined: 20-September 08

Re: using abstract classes and methods compiling error

Posted 06 November 2011 - 09:59 AM

Quote

super("Robin");


The superclass of Robin (Bird) does not have the constructor that you're trying to invoke, i.e. a ctor that takes one String
Was This Post Helpful? 0
  • +
  • -

#3 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10803
  • View blog
  • Posts: 40,257
  • Joined: 27-December 08

Re: using abstract classes and methods compiling error

Posted 06 November 2011 - 09:59 AM

Look at the Bird constructor: public Bird(String name, String breed). It accepts both a name and breed as parameters. Also, why extend Bird if you have a breed field in Bird already? It seems contradictory and redundant.
Was This Post Helpful? 1
  • +
  • -

#4 AMZDeCoder  Icon User is offline

  • D.I.C Head

Reputation: 25
  • View blog
  • Posts: 102
  • Joined: 04-November 11

Re: using abstract classes and methods compiling error

Posted 06 November 2011 - 10:20 AM

Add a constructor to your Bird class one which takes a single paramater which is the Bird name.
Was This Post Helpful? 0
  • +
  • -

#5 nielatjie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 28-August 11

Re: using abstract classes and methods compiling error

Posted 07 November 2011 - 06:56 AM

Thanks it is working now!!!

Ok now they ask me to create a dog class and fish class inheriting from Animal

I did the 2 classes but now there is this question and I have no idea what to do

Re-write AbstractTest as LoopTest.java. Create an array of Animal and then loop through the array using an enchanced for(), calling the describe(), sound(), sleep() and move() methods succesively

and the second question is

Change LoopTest.java to use an ArrayList instead of an array.

Can somebody please help me I really don't know what to do and I'm a distance learner the people on the Helplines don't understand me!
Was This Post Helpful? 0
  • +
  • -

#6 Veitch  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 27
  • View blog
  • Posts: 59
  • Joined: 05-November 11

Re: using abstract classes and methods compiling error

Posted 07 November 2011 - 07:02 AM

What exactly is it you don't understand?
If you don't know what an enhanced for loop it look here: http://download.orac...dbolts/for.html
If you don't know how to use an ArrayList look here: http://javarevisited...a-tutorial.html

If it is something else, ask a specific question.
Was This Post Helpful? 0
  • +
  • -

#7 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10803
  • View blog
  • Posts: 40,257
  • Joined: 27-December 08

Re: using abstract classes and methods compiling error

Posted 07 November 2011 - 07:10 AM

Locke has a tutorial on ArrayLists vs. static arrays as well.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1