Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Description: In this activity you will learn when and how to use the super keyword. You will create a tortoise and turtle who are both

Description:

In this activity you will learn when and how to use the super keyword. You will create a tortoise and turtle who are both reptiles. You will use the reptile whoAmI and modify it to get the required output. Please follow the steps below:

Steps:

  1. Read the explanation and observe how the super keyword is used in the Tortoise.java file.
  2. Create a class Turtle that inherits from Reptile.
  3. Create a instance variable that will hold the length of time our turtle will hold it's breath.
  4. Make a constructor that takes in variables for the reptile super constructor. Make sure to get a value in the constructor to initialize breath.
  5. Override the whoAmI() method. Make sure to print this out: " and a turtle. My skin is scaly utilitzing the super keyword. I can hold my breath for 60 minutes."
  6. Create a Tortoise object that utilized our Toroise constructor which takes in the name, limbs and life. Assign those values in our object and get the return of. The name should be Baloo, limbs should be bent and stubby, and life should be 150 years.
  7. Call the whoAmI method using your Tortoise object.
  8. Create a Turtle object that utilized our Turtle constructor which takes in the name, limbs, life and breath. The Name should be Squirtle, limbs should be flippers, life should be 50 and breath should be 60.
  9. Call the whoAmI method using your Turtle object.

Test:

Use the test provided.

Sample output:

 

My name is Baloo. I am a reptile and a tortoise. My skin is scaly.

My name is Squirtle. I am a reptile and a turtle. My skin is scaly. I can hold my breath for 60 minutes.

class Main {

String name = "Baloo";

String limbs= "Bent";

int life=150;

String tname="";

String tlimbs="";

int tlife;

int breath;

public Main(String tname,String tlimbs, int tlife, int breath){

this.tname = tname;

this.tlimbs = tlimbs;

this.tlife=tlife;

this.breath=breath;

}

public Main(String name, String limbs, int life) {

this.name = name;

this.limbs = limbs;

this.life =life;

}

public String returnName() {

return name;

}

public String returnLimbs() {

return limbs;

}

public int returnLife() {

return life;}

public String returnTname() {

return tname;}

public String returnTLimbs() {

return tlimbs;}

public int returnTlife() {

return tlife;}

public int returnbreath() {

return breath;}

public void whoAmI(){

System.out.print("My name is " + name + ". I am a reptile");

}

public void whoAmIt(){

System.out.print("My name is " + tname + ". I am a Turtle ");

}

}

// 6. Create a Tortoise object that utilized our Tortoise constructor which takes in the name, limbs and life. Assign those values in our object and get the return of. The name should be Baloo, limbs should be bent and stubby, and life should be 150 years.

// 7. Call the whoAmI method using your Tortoise object.

// 8. Create a Turtle object that utilized our Turtle constructor which takes in the name, limbs, life and breath. The Name should be Squirtle, limbs should be flippers, life should be 50 and breath should be 60.

// 9. Call the whoAmI method using your Turtle object.

class Reptile {

String skin = "scaly";

String name;

String limbs;

int life;

public Reptile(String name, String limbs, int life){

this.name = name;

this.limbs = limbs;

this.life = life;

}

public void whoAmI(){

System.out.print("My name is " + name + ". I am a reptile");

}

}

class Tortoise extends Reptile {

String name = "Baloo";

String limbs= "Bent";

int life=150;

boolean parent;

// 1. The parameters that are passed into the super() method here are called from the parent Class constructor. The super here takes in the name, limbs, and life and uses the Reptile constructor in order to create the Tortoise. As we need the same fields associated with the reptiles as a tortoise is a reptile.

public Tortoise(String name, String limbs, int life){

super(name, limbs, life);

parent = false;

}

@Override

public void whoAmI(){

super.whoAmI();

System.out.println(" and a tortoise. My skin is " + super.skin + ".");

}

}

// 2. Create a class Turtle that inherits from Reptile.

class Turtle extends Reptile{

String name = "yyy";

String limbs= "ljkj";

int life=100;

int breath= 60;

boolean parent;

public Turtle(String name, String limbs, int life, int breath){

super(name, limbs, life, breath);

parent = false;

}

// 3. Create a instance variable that will hold the length of time our turtle will hold it's breath.

// 4. Make a constructor that takes in variables for the reptile super constructor. Make sure to get a value in the constructor to initialize breath.

public void whoAmI(){

super.whoAmI();

System.out.println(" I can hold my breath for" + super.breath + ".");

}

//create instances here

// 5. Override the whoAmI() method. Make sure to use the super method like in the Tortoise class. Sample output for whoAmI: "My name is Squirtle. I am a reptile and a turtle. My skin is scaly. I can hold my breath for 60 minutes."

}

Here is all info that I hava.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions

Question

=+ d. Income per worker in Richland is actually

Answered: 1 week ago