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
A computer's hard disk drive holds 8 x 10^10 bytes of information. If Jill buys an extra memory stick that holds 5.1 X 10^8 byte
denis-greek [22]

Answer:

The computer will store 8.05 *10^10 bytes of information.

Explanation:

This is the same as saying that the computer will now have 80.51 Gigabytes ( 1gb = 1.000.000.000 bytes) of storage. In this case, the number is represented in its decimal form, and the previous one is displayed in Scientific Notation.

8 0
2 years ago
“When using a public computer for browsing the Internet, try to use for 1.________ transactions. Also, use 2.__________ browsing
Tamiku [17]

option 2 is c

option 1is B

3 0
3 years ago
Read 2 more answers
A customer wants to purchase a new home computer. The machine will mainly be used for internal browsing and streaming video, exc
Gekata [30.6K]

Answer:

Four-core processor

Explanation:

A four-core processor also known as a quad-core processor has four units cores that are independent and are responsible for reading and executing instruction in the central processing unit of a computer or system. It has high processing speed and is the best for gaming, and for multitasking purposes.

4 0
3 years ago
Hich chip contains the information necessary to start the computer system?
Sindrei [870]
The BIOS contains the information.
7 0
3 years ago
Which is a network of devices built around a person, typically within 10 meters of range?
11111nata11111 [884]

Answer:

A LAN

Explanation:

A LAN, or a Local Area Network, is a network of devices typically within 10 meters of range regardless of what it is built around.

6 0
3 years ago
Other questions:
  • An IT technician has manually configured an IP address on a laptop for a new employee. Each time the employee tries to connect t
    8·1 answer
  • Which statement is true? Group of answer choices Variables cannot be assigned and declared in the same statement Variable names
    5·1 answer
  • Which of the following sentences uses the correct verb tense?
    8·2 answers
  • In the code segment below, assume that the int variable n has been properly declared and initialized. The code segment is intend
    5·1 answer
  • ____ technology is the same as that used in digital watches, or the time display on a microwave oven
    14·1 answer
  • In Python what are the values passed into functions as input called?
    13·1 answer
  • Suggest three ways in which celebrating an occasion influences food choices?
    10·2 answers
  • What is software? Why is it needed?​
    6·1 answer
  • Every windows service has the 3 start types what are those service types?
    15·1 answer
  • What would the input, process, outcome and feedback be for a class assignment
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!