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
mrs_skeptik
1 month 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:
ivann1987 [930]1 month ago
8 0

Answer:

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

   super.printAll(); //  invokes printAll() method from the superclass (base class) AnimalData using the super keyword

   System.out.print(", ID: " + idNum);} // displays the ID saved in the idNum field of the PetData class

Explanation:

This is the full PetData class:

public class PetData extends AnimalData { //

private int idNum;

public void setID(int petID) {

idNum = petID; }

// FIXME: Implement printAll() member method

/* Your solution goes here */

public void printAll(){

   super.printAll();

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

The PetData class is a subclass that inherits from the base class AnimalData.

This class contains a private field, idNum, which is designated for storing the ID value.

It includes a method setID which takes petID as a parameter that corresponds to idNum. Essentially, this acts as a mutator to set the user ID.

Additionally, there is a printAll() method that makes use of the super keyword to call the printAll() method from the base class, AnimalData.

Using super refers to objects of the base class.

Here, the super keyword is utilized with the method name from the subclass PetData to avoid confusion, as both AnimalData and PetData have a method named printAll().

During the main() method, users will enter values for userName, UserAge, and UserID. For example, if the user inputs Fluffy as the name, 5 as the age, and 4444 as the userID. Then, calling userPet.printAll(); will execute the printAll() method from the PetData class since userPet is an instance of PetData.

When this method executes, it will call the printAll() of AnimalData class which outputs the Name and Age, while printAll() of PetData prints the ID. Consequently, the resulting output will be:

Name: Fluffy, Age: 5, ID: 4444

You might be interested in
Exercise 8.1.9: Diving Contest Your school is hosting a diving contest, and they need a programmer to work on the scoreboard! Yo
zubka84 [945]

Response:

def calculate_score(theTuple):

    first, second, third = theTuple

    if first >= 0 and first <=10 and second >= 0 and second <=10 and third >= 0 and third <=10:

         print(first + second + third)

    else:

         print("Range must be 0 to 10")

Clarification:

This line initiates the function

def calculate_score(theTuple):

This line extracts the values used in the function

    first, second, third = theTuple

The subsequent if statement verifies whether the values fall within the 0 to 10 range

    if first >= 0 and first <=10 and second >= 0 and second <=10 and third >= 0 and third <=10:

This computes the total score

         print(first + second + third)

else:

Should the scores be outside the 0 to 10 limits, this line will be executed

         print("Range must be 0 to 10")

4 0
23 days ago
Rewrite following program using for loop no=3456 while no&gt;0 : print(no%10) no=no/10
zubka84 [945]
no=3456 for x in reversed(str(no)): print(x) If you convert the number to a string and reverse it, you will obtain the same outcome.
8 0
20 days ago
Read 2 more answers
You are given a string of n characters s[1 : : : n], which you believe to be a corrupted text document in which all punctuation
ivann1987 [930]

Response: explained in the explanation section

Explanation:

Given that:

Assume D(k) =║ true if [1::: k] is a valid sequence of words, or false otherwise

  • In determining D(n)

the sub problem s[1::: k] is a valid sequence of words IFF s[1::: 1] is valid and s[ 1 + 1::: k] is a valid word.

Thus, we derive that D(k) is defined by the following recurrence relation:

D(k) = ║ false max(d[l] ∧ DICT(s[1 + 1::: k]) otherwise

Algorithm:

Valid sentence (s,k)

D [1::: k]             ∦ array of boolean variables.

for a ← 1 to m

do;

d(0) ← false

for b ← 0 to a - j

for b ← 0 to a - j

do;

if D[b] ∧ DICT s([b + 1::: a])

d (a) ← True

(b). Algorithm Output

      if D[k] == True

stack = temp stack            ∦stack assists in displaying the strings in order

c = k

while C > 0

stack push (s [w(c)]::: C] // w(p) denotes the index in s[1::: k] of the valid word // at position c

P = W (p) - 1

output stack

= 0 =

cheers, I hope this aids you!!!

8 0
16 days ago
Sushant is a new manager and he wants to share his ideas and working protocol with his team.Compare the advantages and disadvant
oksian1 [804]

Answer:

Benefits of Oral Communication

  1. Utilizing visual aids such as PowerPoint during discussions can enhance his team's understanding of his concepts and procedures.
  2. Staff responses tend to be more immediate and sincere compared to written replies.

Drawbacks of Oral Communication

  1. If Sushant struggles with stage fright or lacks strong communication skills, it may negatively impact the team's perception of him.
  2. There is a risk that staff may forget portions of Sushant's spoken communication, as written information is generally more reliable for retention.

Benefits of Written Communication

  1. A well-crafted memo articulates Sushant's ideas and procedures clearly to the staff.
  2. A feedback questionnaire could be included for staff input.
  3. Clearly stated goals and objectives.

Drawbacks of Written Communication

  1. Excessively lengthy written material may pose challenges for comprehension or retention.

It is advisable for Sushant to prioritize written communication to share his ideas and protocols effectively.

3 0
1 month ago
Write a function so that the main program below can be replaced by the simpler code that calls function mph_and_minutes_to_miles
Natasha_Volkova [897]

Answer:

def mph_and_minutes_to_miles(hours_traveled, miles_traveled):

   hours_traveled = minutes_traveled / 60

   miles_traveled = hours_traveled * miles_per_hour

   print('Miles: %f' % miles_traveled)

Explanation:

This function, written in Python, specifies two input parameters (hours_traveled, miles_traveled)

When executed, the main function prompts the user for necessary data, calls this method, and passes the inputs as arguments. Refer to the complete code and output that follows.

6 0
28 days ago
Other questions:
  • The compare_strings function is supposed to compare just the alphanumeric content of two strings, ignoring upper vs lower case a
    15·1 answer
  • Write a program that creates a login name for a user, given the user's first name, last name, and a four-digit integer as input.
    6·1 answer
  • Consider a load-balancing algorithm that ensures that each queue has approximately the same number of threads, independent of pr
    14·1 answer
  • Henry, a graphic artist, wants to create posters. Which software should Henry use for this purpose?
    13·1 answer
  • Which of the following is opened when the Find command is clicked?
    12·1 answer
  • When adopting and implementing a Software as a Service (SaaS) platform such as Salesforce for your business, which responsibilit
    7·1 answer
  • A wireless network was recently installed in a coffee shop and customer mobile devices are not receiving network configuration i
    12·1 answer
  • Define a new object in variable sculptor that has properties "name" storing "Michelangelo"; "artworks" storing "David", "Moses"
    12·1 answer
  • The engineering firm you work for is submitting a proposal to create an amphitheater at a state park. Proposals must be submitte
    15·1 answer
  • An application specifies a requirement of 200 GB to host a database and other files. It also specifies that the storage environm
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!