Home / Expert Answers / Computer Science / 10-9-lab-pet-information-derived-classes-the-base-class-pet-has-protected-fields-petname-and-p-pa404

(Solved): 10.9 LAB: Pet information (derived classes) The base class Pet has protected fields petName, and p ...



10.9 LAB: Pet information (derived classes)
The base class Pet has protected fields petName, and petAge. The derived class DoLAB
ACTIVITY
File is marked as read only
1 public class Dog extends Pet {
2
private String breed;
3
4
public void setBreed (SLAB
ACTIVITY
10.9.1: LAB: Pet information (derived classes)
File is marked as read only
1 public class Pet {
2
3
4
5
6
7
8
9
LAB
ACTIVITY
Current file: PetInformation.java ?
1 import java.util.Scanner;
2
3 public class Pet Information {
4 public stat1: Compare output A
Dobby
2
Input
Kreacher
3
German Schnauzer
Your output Your program produced no output
Pet Information:
Na5: Compare output
Whiskers
5
Input
Riley
8
Doberman
Your output Your program produced no output
Pet Information:
Name: Whiske

10.9 LAB: Pet information (derived classes) The base class Pet has protected fields petName, and petAge. The derived class Dog extends the Pet class and includes a private field for dog Breed. 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 LAB ACTIVITY File is marked as read only 1 public class Dog extends Pet { 2 private String breed; 3 4 public void setBreed (String userBreed) { breed userBreed; 5 6 } 7 public String getBreed() { return breed; } 8 10.9.1: LAB: Pet information (derived classes) 9 10 11 } Current file: Dog.java ? 0/10 LAB ACTIVITY 10.9.1: LAB: Pet information (derived classes) File is marked as read only 1 public class Pet { 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 } Current file: Pet.java protected String name; protected int age; public void setName(String userName) { name = userName; } public String getName() { return name; } public void setAge(int userAge) { age userAge; } public int getAge() { return age; } public void printInfo() { System.out.println("Pet Information: "); System.out.println(" Name:" + name); System.out.println(" Age: " + age); } 0/10 LAB ACTIVITY Current file: PetInformation.java ? 1 import java.util.Scanner; 2 3 public class Pet Information { 4 public static void main(String[] args) { 5 Scanner scnr = new Scanner(System.in); 6 7 Pet myPet = new Pet(); Dog myDog = new Dog(); String petName, dogName, dogBreed; int petAge, dogAge; petName= scnr.nextLine(); petAge scnr.nextInt (); scnr.nextLine(); dogName scnr.next(); dogAge scnr.nextInt (); scnr.nextLine(); dog Breedscnr.nextLine(); // TODO: Create generic pet (using petName, petAge) and then call printInfo // TODO: Create dog pet (using dogName, dogAge, dogBreed) and then call printInfo // TODO: Use getBreed(), to output the breed of the dog 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ?27272 10.9.1: LAB: Pet information (derived classes) 26 } 28 } 0/10 Load default template... 1: Compare output A Dobby 2 Input Kreacher 3 German Schnauzer Your output Your program produced no output Pet Information: Name: Dobby Age: 2 Expected output Pet Information: Name: Kreacher Age: 3 Breed: German Schnauzer 2: Compare output Mittens Input Bolt 2 German Shepherd Your output Your program produced no output Pet Information: Name: Mittens Age: 4 Expected output Pet Information: Name: Bolt Age: 2 Breed: German Shepherd Coco 1 Input Simba 2 Poodle Your output Your program produced no output Pet Information: Name: Coco Age: 1 Expected output Pet Information: Name: Simba Age: 2 Breed: Poodle 3: Compare output A 4: Compare output Bojangles 3 Input Eclair 1 Chihuahua Your output Your program produced no output Pet Information: Expected output Name: Bojangles Age: 3 Pet Information: Name: Eclair Age: 1 Breed: Chihuahua 0/2 0/2 0/2 0/2 5: Compare output Whiskers 5 Input Riley 8 Doberman Your output Your program produced no output Pet Information: Name: Whiskers Age: 5 Expected output Pet Information: Name: Riley Age: 8 Breed: Doberman 0/2


We have an Answer from Expert

View Expert Answer

Expert Answer


ANSWER: import java.util.Scanner; public class PetInformation { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); Pet myPet = new Pet(); Dog myDog = new Dog(); String petName, dogNa
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe