Answered step by step
Verified Expert Solution
Question
1 Approved Answer
public class Animal { private String name; private int birthYear; private double weight; private char gender; / / Default constructor Animal ( ) { this.name
public class Animal
private String name;
private int birthYear;
private double weight;
private char gender;
Default constructor
Animal
this.name ;
this.birthYear ;
this.weight ;
this.gender u;
Parameterized constructor
AnimalString name, int year, double weight, char gender
this.name name;
this.birthYear year;
this.weight weight;
this.gender gender;
public String getName
return name;
public int getBirthYear
return birthYear;
public double getWeight
return weight;
public char getGender
return gender;
public void setNameString name
this.name name;
public void setBirthYearint birthYear
this.birthYear birthYear;
public void setWeightdouble weight
if weight
this.weight ;
else
this.weight weight;
public void setGenderchar gender
if gender m && gender f
this.gender u;
else
this.gender gender;
public int calculateAgeint current
if current this.birthYear
return ;
return current this.birthYear;
public boolean isMale
return this.gender m;
public boolean isFemale
return this.gender f;
public void gainWeight
this.weight;
public void gainWeightdouble x
if x
this.weight x;
public void loseWeight
this.weight Math.max this.weight ;
public void loseWeightdouble x
if x
this.weight Math.max this.weight x;
public void printDetails
String name String.formatName: s this.name;
String year String.formatYear of Birth: d this.birthYear;
String w String.formatWeight: f this.weight;
String g String.formatGender: c this.gender;
System.out.printlnname year w g;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started