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
julsineya [31]
3 years ago
6

The base class Pet has private fields petName, and petAge. The derived class Dog extends the Pet class and includes a private fi

eld for dogBreed. Complete main() to:
• create a generic pet and print information using printInfo()
• create a Dog pet, use printInfo() to print information, and add a statement to print the dog's breed using the getBreed() method.
Ex. If the input is:
Dobby
2
Kreacher
3
German
Schnauzer
the output is:
Pet Information:
Name: Dobby
Age: 2
Pet Information:
Name: Kreacher
Age: 3
Breed: German Schnauzer
Computers and Technology
1 answer:
galben [10]3 years ago
7 0

Answer:

Explanation:

The following code is written in Java and creates the needed code within the main method in order to get the desired output as shown in the example. It also added The proper questions so that the user can know what type of information they should type in.

import java.util.Scanner;

public class PetInformation {

   public static void main(String[] args) {

       Scanner scnr = new Scanner(System.in);

       String petName, dogName;

       String dogBreed = "null";

       int petAge, dogAge;

       Pet myPet = new Pet();

       System.out.println("Enter Pet Name:");

       petName = scnr.nextLine();

       System.out.println("Enter Pet Age:");

       petAge = scnr.nextInt();

       Dog myDog = new Dog();

       System.out.println("Enter Dog Name:");

       dogName = scnr.next();

       System.out.println("Enter Dog Age:");

       dogAge = scnr.nextInt();

       scnr.nextLine();

       System.out.println("Enter Dog Breed:");

       dogBreed = scnr.nextLine();

       System.out.println(" ");

       myPet.setName(petName);

       myPet.setAge(petAge);

       myPet.printInfo();

       myDog.setName(dogName);

       myDog.setAge(dogAge);

       myDog.setBreed(dogBreed);

       myDog.printInfo();

       System.out.println(" Breed: " + myDog.getBreed());

   }

}

class Pet {

   protected String petName;

   protected int petAge;

   public void setName(String userName) {

       petName = userName;

   }

   public String getName() {

       return petName;

   }

   public void setAge(int userAge) {

       petAge = userAge;

   }

   public int getAge() {

       return petAge;

   }

   public void printInfo() {

       System.out.println("Pet Information: ");

       System.out.println(" Name: " + petName);

       System.out.println(" Age: " + petAge);

   }

}

class Dog extends Pet {

   private String dogBreed;

   public void setBreed(String userBreed) {

       dogBreed = userBreed;

   }

   public String getBreed() {

       return dogBreed;

   }

}

You might be interested in
Chef is an orchestration tool?<br> Yes or No
nlexa [21]
I believe its yes. you can just look it up 

5 0
4 years ago
Read 2 more answers
Ann. An employee in the payroll department, has contacted the help desk citing multiple issues with her device, including: Slow
coldgirl [10]

Answer:

d. Backdoor

Explanation:

A backdoor is a type of malware that overrides security checks and authentications to access a computer or embedded device.

When this is done, remote access is granted and databases and servers can be accessed and modified. Attackers can also give remote commands to the system.

What happened to Ann in the payroll department is probably a backdoor attack that affected her device.

8 0
3 years ago
Given the Query Data Type, which of the following is incorrectly matched with the corresponding Storage Data Type?
Tamiku [17]

Answer:

<h2>c) Date : Date</h2>

Explanation:

A type of attribute of data is called data type in computer science, data types tells the interpreter how a person wants to use the data. The basic data types are supported by most of the programming languages, the basic data types are Integers, float, characters, strings, point numbers and arrays. The terminology may differ from one language to other.

3 0
3 years ago
Write a program that displays the smallest of five input values that may include duplicate values (e.g., 6, 4, 8, 6, 7). Hint: R
Tpy6a [65]

Answer:

Here the code is given as follows,

Explanation:

Code:-

import java.util.*;

class Chegg {

 

   public static void main(String args[])

   {

       Scanner sc=new Scanner(System.in);

       System.out.println("Enter 5 numbers");

       int arr[]=new int[5];

       int min;

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

       {

           arr[i]=sc.nextInt();

       

       }

       min=arr[0];

       for(int i=1;i<5;i++)

       {

           if(arr[i]<min)

           {

               min=arr[i];

           }

       }

       System.out.println(min);

   }

}

3 0
3 years ago
One common advantage of a long-term investment is
Marizza181 [45]

Answer:

bitcoin

Explanation:

8 0
3 years ago
Other questions:
  • In social networking websites such as twitter, people leave narrow minded and subjective remarks and upload unacceptable videos.
    9·1 answer
  • Create detailed pseudocode for a program that calculates how many days are left until Christmas, when given as an input how many
    15·1 answer
  • Why is it preferable to code web pages in HTML format?
    6·2 answers
  • What is the command to display the user name with which youhave logged in?
    8·1 answer
  • Encapsulation is a form of information hiding and an important characteristic of object-oriented programming. When a programmer
    6·1 answer
  • Design a base class, Road, with the following members:
    13·1 answer
  • The mainframe computer are the ____ and most ____ computers..​
    11·1 answer
  • Question #8
    5·1 answer
  • Un polímero sintético es renovable o no renovable
    11·1 answer
  • What microphone is this
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!