1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Alisiya [41]
3 years ago
13

Define a method printAll() for class PetData that prints output as follows with inputs "Fluffy", 5, and 4444. Hint: Make use of

the base class' printAll() method.
Name: Fluffy, Age: 5, ID: 4444
// ===== Code from file AnimalData.java =====
public class AnimalData {
private int ageYears;
private String fullName;
public void setName(String givenName) {
fullName = givenName;
}
public void setAge(int numYears) {
ageYears = numYears;
}
// Other parts omitted
public void printAll() {
System.out.print("Name: " + fullName);
System.out.print(", Age: " + ageYears);
}
}
// ===== end =====
// ===== Code from file PetData.java =====
public class PetData extends AnimalData {
private int idNum;
public void setID(int petID) {
idNum = petID;
}
// FIXME: Add printAll() member function
/* Your solution goes here */
}
// ===== end =====
// ===== Code from file BasicDerivedOverride.java =====
import java.util.Scanner;
public class BasicDerivedOverride {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
PetData userPet = new PetData();
String userName;
int userAge;
int userID;
userName = scnr.next();
userAge = scnr.nextInt();
userID = scnr.nextInt();
userPet.setName(userName);
userPet.setAge (userAge);
userPet.setID (userID);
userPet.printAll();
System.out.println("");
}
}
// ===== end =====

Computers and Technology
1 answer:
QveST [7]3 years ago
8 0

Answer:

public void printAll(){  // member function petAll()

   super.printAll();  //  calls printAll() method of the superclass (base class) AnimalData using super keyword

   System.out.print(", ID: " + idNum);} // prints the ID stored in the idNum data member of the PetData class

Explanation:

Here is the complete PetData class:

public class PetData extends AnimalData {  //

private int idNum;

public void setID(int petID) {

idNum = petID;  }

// FIXME: Add printAll() member function

/* Your solution goes here */

public void printAll(){

   super.printAll();

   System.out.print(", ID: " + idNum);}  }

PetData class is a subclass which is inherited from the base class AnimalData.

This class has a private data member which is the variable idNum which is used to store the ID value.

It has a member function setID with parameter petID which is the idNum. This method basically acts as a mutator and sets the user ID.

This class has another method printAll() that uses super keyword to access the method printAll() of the base class which is AnimalData

super basically refers to the base class objects.

Here the super keyword is used with the method name of subclass PetData in order to eliminate the confusion between the method printAll() of AnimalData and PetData since both have the same method name.

In the main() method the use is prompted to enter values for userName, UserAge and UserID. Lets say user enters Fluffy as user name, 5 as user age and 4444 as userID. Then the statement userPet.printAll(); calls printAll() method of PetData class as userPet is the object of PetData class.

When this method is called, this method calls printAll() of AnimalData class which prints the Name and Age and printAll() of PetData class prints the ID. Hence the program gives the following output:

Name: Fluffy, Age: 5, ID: 4444    

You might be interested in
Create a new Die object. (Refer to Die.html for documentation.)Create a loop that will iterate at least 100 times. In the loop b
hjlf

Answer:

Java code is given below

Explanation:

import java.util.Random;

class Die{

private int sides;

public Die(){

sides = 6;

}

public Die(int s){

sides = s;

}

public int Roll(){

Random r = new Random();

return r.nextInt(6)+1;

}

}

class DieRoll{

public static void main(String[] args) {

Die die = new Die();

int arr[] = new int[6];

for(int i=0; i<6; i++)

arr[i] = 0;

for(int i=0; i<100; i++){

int r = die.Roll();

arr[r-1]++;

}

for(int i=0; i<6; i++)

System.out.println((i+1)+" was rolled "+arr[i]+" times.");

}

}

8 0
3 years ago
For whover needed pont
podryga [215]

Answer:

Thank you have a nice day:)

8 0
2 years ago
Read 2 more answers
Most people prefer to pay health insurance premiums rather than pay out of pocket for medical expenses because
oksano4ka [1.4K]
They may not have enough money for the bill at the time, and its easier to pay for insurance for unseen medical procedures.
7 0
3 years ago
Read 2 more answers
Which sentence uses parallel structure correctly?
Archy [21]

Answer: Correct option is Option D.

Explanation:

Processed foods are bad for you, are high in fat, and are the cause of serious health issues.

Parallel structures are those structures where words are used in same pattern in a sentence to show that two given ideas/phrases are of similar significance.

This sentence uses parallel structure correctly.

Parallel structure in the sentence are -

are bad for you

are high in fat

are the cause of serious health issues

3 0
2 years ago
Chang is a network engineer. He is revising the company's firewall implementation procedure. As part of this work, he is reviewi
erastovalidia [21]

Answer:

d

Explanation:

3 0
2 years ago
Other questions:
  • You have decided to remove a recently installed feature which method can you use to remove this feature
    13·1 answer
  • What is a directory server?
    5·1 answer
  • Mohammed's parents learn that his classmates have
    7·2 answers
  • Translate I don't sing into Spanish​
    11·2 answers
  • Suppose we are comparing the implementations of insertion sort and merge sort on the same machine(You don’t need to know the alg
    13·1 answer
  • Which screen should be open to customize or personalize a desktop background?
    15·2 answers
  • Write an algorithm to find the average of three numbers: 10, 20, 30
    7·1 answer
  • Podcasts can only be created by professional organizations
    11·2 answers
  • Imagine an everyday scenario in which you are using the internet: downloading a file, uploading a photo, checking your email, et
    5·1 answer
  • In python please:
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!