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
As in algebra, you can use brackets to override the order of operations Excel follows to perform formula calculations. True or f
sertanlavr [38]

Answer:

false

Explanation:

parasynthesis is used to change the order of priority.

6 0
3 years ago
In 3-5 sentences, describe how you would insert a graph in your word-processing document.
Allisa [31]

Answer:

Click the “Insert” tab, then click the “Chart” button on the Illustrations section to open the “Insert Chart” pop-up window.

Select the type of graph to add to the document, such as a pie chart or bar graph. ...

Click “OK” and Word adds a chart with generic data points to the document.

Explanation:

3 0
3 years ago
Given an int as the input, print all the factors of that number, one in each line. For example, if the input is 15 The output wi
trapecia [35]

Answer:

The program to calculate factor can be given as:

Program:

#include <stdio.h> //include header file

int main() //defining main function

{

   int a,i; //defining integer variable

   printf("Enter any number: "); //print message

   scanf("%d",&a); //input value from user end

   for(i=1;i<=a;i++) //loop for calculate factor values

   {

       if(a%i==0) //define condition for factor

       {

           printf("%d\n",i); //print values

       }

   }

   return 0;

}

Output:

Enter any number: 15

1

3

5

15

Explanation:

In the above C language program the header file is include that provide the use of basic function, in the next line the main method is defined, inside this method two integer variable "a and i" is defined in which variable a is used to take value from user end and variable i is used in loop and conditional statement.

  • In the next step, for loop is declare, that start from 1 and end with value of variable a, inside a loop, if block is used that checks (a%i==0), in this if variable i value modeler value equal to 0.  
  • The loop will use the print function that prints variable "i" element in a new line, which is the factor the values.  

4 0
2 years ago
Read 2 more answers
What does the term World Wide Web refer to?
Katena32 [7]
The internet because its world wide because our computers and everything are all inter twined making a world wide web Hope this helps
3 0
2 years ago
Read 2 more answers
Assume in the for loop header, the range function has the three arguments: range (1, 10, 3), if you were to print out the value
Licemer1 [7]

Answer:

1, 4, 7

Explanation:

The instruction in the question can be represented as:

for i in range(1,10,3):

   print i

What the above code does is that:

It starts printing the value of i from 1

Increment by 3

Then stop printing at 9 (i.e.. 10 - 1)

So: The sequence is as follows

Print 1

Add 3, to give 4

Print 4

Add 3, to give 7

Print 7

Add 3, to give 10 (10 > 10 - 1).

So, it stops execution.

6 0
2 years ago
Other questions:
  • Which of these is an aggregator?
    9·2 answers
  • Why are computer programs so much longer now than they were in the late 1980?
    8·1 answer
  • Which features would work well for text entered into cells? Check all that apply.
    5·2 answers
  • How can I sent a message?
    13·1 answer
  • Mary is entering her senior year of college. She has a meeting on Friday with her advisor to discuss her career plans.Mary is al
    15·1 answer
  • For each 8-bit data frame the layer uses a generator polynomial G(x) = x4+x2+ x+1 to add redundant bits. What is the sequence of
    11·1 answer
  • A system administrator is selecting an operating system for use by the company’s research and development team. The team require
    15·1 answer
  • A palindrome is a string that reads the same both forward and backward. For example, the string madam is a palindrome. Write a p
    13·1 answer
  • What do I do if my friend wants me to watch a video at my house?
    8·2 answers
  • How can injection attacks be prevented? Check all that apply
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!