The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 398 Weeks Ago, 3 Days Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
Guys I have some problems with this code. It wouldn't compile.
Â
public class Driver
{
public static void main(String[] args)
{
Pet p = new Pet("Terrance");
p.printInfo();
System.out.println();
Mammal m = new Mammal();
m.printInfo();
m.setName("Roxie");
m.printInfo();
System.out.println();
Fish f = new Fish("red");
f.printInfo();
f.setName("Shark");
f.printInfo();
System.out.println();
Dog d = new Dog("Watson", "Basset");
d.printInfo();
}
}
Â
----------------------------------------
Â
public class Pet
{
protected String name;
public Pet(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void setName(String inName)
{
name = inName;
}
public void printInfo()
{
System.out.println("The pet's name is " + name);
}
}
Â
---------------------------------
Â
public class Fish extends Pet
{
protected String color;
public Fish(String name, String color)
{
super(name);
this.color = color;
}
public void printInfo()
{
super.printInfo();
System.out.println("The fish is " + color + "and its name is " + getName());
}
}
Â
----------------------------------
Â
public class Mammal extends Pet
{
Â
public Mammal(String name)
{
super(name);
}
public void setName(String inName)
{
name = inName;
}
public void printInfo()
{
//System.out.println("The pet's name is " + name);
}
}
Â
--------------------------------
Â
public class Dog extends Mammal
{
public Dog(String name)
{
super(name);
}
public void printInfo()
{
System.out.println("The dog's name is " + name + "and " + name);
}
}
Â
-----------------------------
Â
I need help please!
Â
----------------------------
Â
This is the output that should be printed:
The pet's name is Terrance The pet's name is fluffy The pet's name is Roxie The fish is red and its name is swimmy The fish is red and its name is Shark The dog's name is Watson and it's a Basset
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll