answer.
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]
2 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]2 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
When performing actions between your computer and one that is infected with a virus, which of the following offers NO risk of yo
DochEvi [55]
What are the options?
3 0
2 years ago
Read 2 more answers
What will the output of this program be when it is executed? def test_function( length, width, height): print ("the area of the
erastova [34]

Answer: stuff

Explanation:

6 0
2 years ago
Cathy connected a keyboard, mouse, and printer to her computer through a Bluetooth connection. What type of network has she crea
Zielflug [23.3K]

The answer to the given question is (B) PAN.

A PAN (personal area network) connection is <u>a network used for interconnecting devices centered on a person’s workspace</u>. Bluetooth is a type of wireless PAN. Bluetooth-based wireless PAN connection is also called a <em>piconet</em>. Other examples of PAN that is not wireless based include a USB drive.

4 0
2 years ago
Read 2 more answers
PLEASE HELP PROGRAMMING WILL GIVE BRAINLIEST
JulijaS [17]
The fourth choice is correct.
5 0
2 years ago
Which formula would you enter into C3, and then AutoFill into C4 through C6, to calculate the percent sales (Pct.) for the regio
inna [77]

Answer:

In C3, you would enter the formula:

  • =B3/$B$7%

Explanation:

Let's assume the first row is 1 and it contains the titles of the columns.  For instance, the content of the cellss A1:C1 could be:

  • A1: Region
  • B1: Sales
  • C1: Percent Sales

Also, assume the second row is empty and the cells on the first column, A, contain the names of four regions. For instance, North, South, East, and West:

  • A3: North
  • A4: South
  • A5: East
  • A6: West

The cells B3:B6 contain the sales for the four regions. For instance:

  • B3: 200
  • B4: 300
  • B5: 100
  • B6: 400

Then, you must calculate the percent sales for every region, in the cells <em>C3:C6.</em>

That means, you must divide the sale of every region by the total of sales and multiply by 100.

To do that in the worksheet you do this:

<u>1. Sum the sales for the regions:</u>

  • In cell B7 introduce: =SUM(B3:B6)

<u>2. Calculate the percent sale for the first region:</u>

  • In cell C3 introduce: =B3/$B$7%

That means that the reference B3 is relative: when you copy that formula, the column (B) and the row (3) will change accordingly to the cell where you will copy it.

Thus, by using the Autofill into C4 through C6, the column wil remain unchanged (C) and the row will change to 4, 5, and 6, respectively.

The symbol $ used in $B$7 make the reference absolute. That means that they will not change. The symbol % makes that the result is multiplied by 100.

<u>3. When you use Autofull into C4 through C6, you obtain:</u>

  • C4: =B4/$B$7%
  • C5: =B5/$B$7%
  • C6: =B6/$B$7%
4 0
2 years ago
Other questions:
  • how do you make a circuit so 1 switch will turn on/off all the lights(3 lights) and a second switch will change the lights from
    14·2 answers
  • Name an analog quantity other than temperature and sound.
    14·1 answer
  • What is the 5 basic steps of computer programing?
    6·1 answer
  • 1A network administrator notices that some newly installed Ethernet cabling is carrying corrupt and distorted data signals. The
    5·1 answer
  • _____ computing refers to a computing environment that is always present, can feel our surroundings, and-based on who we are, wh
    8·1 answer
  • Universal Containers recently rolled out a Lightning Knowledge implementation; however, users are finding unreliable and unrelat
    6·1 answer
  • There are two methods of enforcing the rule that only one device can transmit. In the centralized method, one station is in cont
    5·1 answer
  • Write an expression that executes the loop body as long as the user enters a non-negative number. Note: If the submitted code ha
    7·1 answer
  • Design an algorithm for a bounded-buffer monitor in which the buffers (portions) are embedded within the monitor itself."
    10·1 answer
  • Write a function in the cell below that iterates through the words in file_contents, removes punctuation, and counts the frequen
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!