Given the main class Dog, subclass Poodle, and the beginning of the subclass Pug: Instructions for Pug.java Variables: int flabCount – the count of layers on the Pug An invalid value should default this field to 25. A value is invalid if it is nonpositive. boolean isPound – whether this Pug resides in the pound. Poodle bestFriend- a Poodle who is the best friend with the Pug Constructors: A constructor that takes in name, length, weight, stripeCount, isSaltwater, and bestFriend. The bestFriend argument should be deep copied. A constructor that takes in no parameters and sets name to “Pluto”, length to 30.0, weight to 320.0, stripeCount to 14, isPound to false, and bestFriend to null. A copy constructor that deep copies all necessary instance fields. Methods: migrate The pug  moves to the opposite kind of living situation if and only if it does not have a best friend.  For example, if this pug were now in a pound and it has a best friend, it would not migrate to a house but instead stay in the pound. toString  Overrides the corresponding method in its super class, such that a String with the following format is returned without trailing or leading whitespace. “I’m a talking dog named . My length is ft in and my weight is lbs oz. I’m a {pound/house} pug with layers. I have {no best friend/a best friend} named }.” No getters or setters should be written. 1. Would I do the below to set the default for flabCount? if(int flabCount < 0) this.flabcount = 25? 2. Am I creating the migrate method correctly and if so, how would I go about creating the toString method and calling a name from Poodle for it? 3. Is that the correct notation to deep copy bestFriend and is there anything else that needs fixing to match the instructions?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Given the main class Dog, subclass Poodle, and the beginning of the subclass Pug:

Instructions for Pug.java

Variables:

  • int flabCount – the count of layers on the Pug
  • An invalid value should default this field to 25.
    • A value is invalid if it is nonpositive.
  • boolean isPound – whether this Pug resides in the pound.
  • Poodle bestFriend- a Poodle who is the best friend with the Pug

Constructors:

  1. A constructor that takes in name, length, weight, stripeCount, isSaltwater, and bestFriend.
  • The bestFriend argument should be deep copied.
  1. A constructor that takes in no parameters and sets name to “Pluto”, length to 30.0, weight to 320.0, stripeCount to 14, isPound to false, and bestFriend to null.
  2. A copy constructor that deep copies all necessary instance fields.

Methods:

  • migrate
  • The pug  moves to the opposite kind of living situation if and only if it does not have a best friend. 
  • For example, if this pug were now in a pound and it has a best friend, it would not migrate to a house but instead stay in the pound.
  • toString
  •  Overrides the corresponding method in its super class, such that a String with the following format is returned without trailing or leading whitespace.
  • “I’m a talking dog named <name>. My length is <feet> ft <inches> in and my weight is <pounds> lbs <ounces> oz. I’m a {pound/house} pug with <flabCount> layers. I have {no best friend/a best friend} named <bestFriendName>}.”
  • No getters or setters should be written.

1. Would I do the below to set the default for flabCount?

if(int flabCount < 0)
this.flabcount = 25?

2. Am I creating the migrate method correctly and if so, how would I go about creating the toString method and calling a name from Poodle for it?

3. Is that the correct notation to deep copy bestFriend and is there anything else that needs fixing to match the instructions?



public class Dog {
// Variables
protected String name;
protected Double length;
protected Double weight;
protected static int totalDogs = 0;
}
// Constructors
public Dog (String name, Double length, Double weight) {
if(name == null || name.trim().isEmpty()) {
this.name = "Clifford";
} else {
this.name = name;
}
if(length == null || length.isNaN() || length.isInfinite() || length < 0) {
this.length = 8.0;
} else {
this.length = length;
if(weight == null || weight.isNaN() || weight.isInfinite() || weight < 0) {
this.weight = 2.0;
} else {
this.weight = weight;
totalFish++;
public Dog() {
//Methods
this("Clifford", 5.0, 12.0);
}
public Fish (Fish other) {
this.name = other.name;
this.length = other.length;
this.weight = other.weight;
totalFish++;
public String format Length() {
int feet = (int) (length / 12);
double inches = length % 12;
inches = (int) (inches * 100.0) / 100.0;
return String.format("%d ft %.2f in", feet, inches);
}
public String formatWeight() {
int pounds = (int) (weight / 16);
double ounces = weight % 16;
ounces = (int) (ounces * 100.0) / 100.0;
if (pounds == 1) {
return String.format("%d lb %.2f oz", pounds, ounces);
} else {
return String.format("%d lbs %.2f oz", pounds, ounces);
}
}
public String toString() {
return String.format("I'm a talking Dog named %s. My length is %s and my weight is %s.",name, format Length(), formatWeight());
public class Poodle extends Dog{
private Double whiskerLength;
public Poodle(String name, double length, double weight, double whiskerLength) {
super (name, length, weight);
setWhiskerLength (whiskerLength);
totalDogs++;
}
public Poodle() {
}
public Catfish (Catfish other) {
this.name = other.name;
this.length = other.length;
this.weight = other.weight;
this.whiskerLength = other.whiskerLength;
totalDogs++;
super("Bluu", 52.0, 720.0);
setWhiskerLength (5.0);
totalDogs++;
}
public Boolean isHairy() {
}
}
return whiskerLength > (length * 12);
@Override
public String toString() {
String hairy = isHairy() ? "am" : "am not";
return String.format("I'm a talking dog named %s. My length is %s ft %s in and my weight is %s lbs %s oz." +
"I'm a Poodle whose longest whisker is %d, so I am %s", name, formatLength(), formatWeight(), whiskerLength, hairy);
public void setWhiskerLength(double whiskerLength) {
if (Double.isNaN(whiskerLength) || Double.isInfinite(whiskerLength) || whiskerLength <= 0) {
} else {
Ln 36, Col 17
this.whiskerLength = 8.0;
this.whiskerLength = whiskerLength;
Transcribed Image Text:public class Dog { // Variables protected String name; protected Double length; protected Double weight; protected static int totalDogs = 0; } // Constructors public Dog (String name, Double length, Double weight) { if(name == null || name.trim().isEmpty()) { this.name = "Clifford"; } else { this.name = name; } if(length == null || length.isNaN() || length.isInfinite() || length < 0) { this.length = 8.0; } else { this.length = length; if(weight == null || weight.isNaN() || weight.isInfinite() || weight < 0) { this.weight = 2.0; } else { this.weight = weight; totalFish++; public Dog() { //Methods this("Clifford", 5.0, 12.0); } public Fish (Fish other) { this.name = other.name; this.length = other.length; this.weight = other.weight; totalFish++; public String format Length() { int feet = (int) (length / 12); double inches = length % 12; inches = (int) (inches * 100.0) / 100.0; return String.format("%d ft %.2f in", feet, inches); } public String formatWeight() { int pounds = (int) (weight / 16); double ounces = weight % 16; ounces = (int) (ounces * 100.0) / 100.0; if (pounds == 1) { return String.format("%d lb %.2f oz", pounds, ounces); } else { return String.format("%d lbs %.2f oz", pounds, ounces); } } public String toString() { return String.format("I'm a talking Dog named %s. My length is %s and my weight is %s.",name, format Length(), formatWeight()); public class Poodle extends Dog{ private Double whiskerLength; public Poodle(String name, double length, double weight, double whiskerLength) { super (name, length, weight); setWhiskerLength (whiskerLength); totalDogs++; } public Poodle() { } public Catfish (Catfish other) { this.name = other.name; this.length = other.length; this.weight = other.weight; this.whiskerLength = other.whiskerLength; totalDogs++; super("Bluu", 52.0, 720.0); setWhiskerLength (5.0); totalDogs++; } public Boolean isHairy() { } } return whiskerLength > (length * 12); @Override public String toString() { String hairy = isHairy() ? "am" : "am not"; return String.format("I'm a talking dog named %s. My length is %s ft %s in and my weight is %s lbs %s oz." + "I'm a Poodle whose longest whisker is %d, so I am %s", name, formatLength(), formatWeight(), whiskerLength, hairy); public void setWhiskerLength(double whiskerLength) { if (Double.isNaN(whiskerLength) || Double.isInfinite(whiskerLength) || whiskerLength <= 0) { } else { Ln 36, Col 17 this.whiskerLength = 8.0; this.whiskerLength = whiskerLength;
public class Pug extends Dog {
private int flabCount;
private Boolean isPound;
private Poodle bestFriend;
}
public Pug (String name, double length, double weight, int stripeCount, boolean isPound, Poodle bestFriend) {
super (name, length, weight);
this.flabCount =
flabcount;
this.isPound = isPound;
this.bestFriend (bestFriend != null) ? new Poodle (bestFriend) : null;
totalDogs++;
}
public Pug() {
}
}
super("Pluto", 30.0, 320.0);
this.isPound = false;
this.bestFriend
totalDogs++;
public Pug (StripedBass other) {
this.name = other.name;
this.length = other.length;
this.weight other.weight;
this.stripeCount = other.stripeCount;
this.isSaltwater
= other.isSaltwater;
this.bestFriend = this.bestFriend = (other.bestFriend != null) ? new Catfish(other.bestFriend) : null;
totalDogs++;
}
=
=
null;
public void migrate() {
==
if (bestFriend null) {
isPound = !isPound;
}
Transcribed Image Text:public class Pug extends Dog { private int flabCount; private Boolean isPound; private Poodle bestFriend; } public Pug (String name, double length, double weight, int stripeCount, boolean isPound, Poodle bestFriend) { super (name, length, weight); this.flabCount = flabcount; this.isPound = isPound; this.bestFriend (bestFriend != null) ? new Poodle (bestFriend) : null; totalDogs++; } public Pug() { } } super("Pluto", 30.0, 320.0); this.isPound = false; this.bestFriend totalDogs++; public Pug (StripedBass other) { this.name = other.name; this.length = other.length; this.weight other.weight; this.stripeCount = other.stripeCount; this.isSaltwater = other.isSaltwater; this.bestFriend = this.bestFriend = (other.bestFriend != null) ? new Catfish(other.bestFriend) : null; totalDogs++; } = = null; public void migrate() { == if (bestFriend null) { isPound = !isPound; }
Expert Solution
steps

Step by step

Solved in 6 steps

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education