Code in JAVA
UML
//TEST HARNESS
//DO NOT CHANGE CODE FOR TEST HARNESS
import java.util.Scanner; // Scanner class to support user input public class TestPetHierarchy { /* * All the 'work' of the process takes place in the main method. This is actually poor design/structure, * but we will use this (very simple) form to begin the semester... */ public static void main( String[] args ) { /* * Variables required for processing */ Scanner input = new Scanner( System.in ); // Set the keyboard as the input device for this process input.useDelimiter( "[\\n\\r]" ); // Correction to allow smoother keyboard input here String name, // These String objects will hold the user input to be used species, // when calling the full constructor method of class Pet. owner, // For simplicity, we have used the same names here as the birthday, // names given to the instance variables in the Class definitions. vax, enviro; boolean again = true; // This boolean controls the while loop we will use. String response; // This String holds the user's response re: continuing the loop. int type = 1; // This int will indicate whether the pet is a Mammal or Reptile String prompt1 = "Please enter the pet's name: "; String prompt2 = "Please enter the pet's owner's name: "; String prompt3 = "Please enter the pet's birthday in yyyy/mm/dd format: "; String prompt4 = "Is the pet a Mammal (1) or a Reptile (2)? "; String promptR1 = "Please enter the Reptile's species: "; String promptR2 = "Please enter a description of the Reptile's required environment: "; String promptM1 = "Please enter the Mammal's species: "; String promptM2 = "Please enter the date of next required vaccinations in yyyy/mm/dd format: "; Pet spot = new Pet( ); // This is simply a 'holding spot' for the object(s) we create. while( again ) // Continue the loop until the user says otherwise... { // Collect necessary and basic Pet input from the user System.out.println( prompt1 ); name = input.next( ); System.out.println( prompt2 ); owner = input.next( ); System.out.println( prompt3 ); birthday = input.next( ); // Prompt as to whether this Pet will be a Mammal or a Reptile System.out.println( prompt4 ); type = input.nextInt( ); if( type == 2) // Unless we know it's a Reptile, we'll assume Mammal... { // Finish collecting information to instantiate a Reptile object System.out.println( promptR1 ); species = input.next( ); System.out.println( promptR2 ); enviro = input.next( ); spot = new Reptile( name, // Actual instantiation of the Reptile object owner, birthday, species, enviro ); } // complete Reptile else { // Finish collecting information to instantiate a Mammal object System.out.println( promptM1 ); species = input.next( ); System.out.println( promptM2 ); vax = input.next( ); spot = new Mammal( name, // Actual instantiation of the Mammal object owner, birthday, species, vax ); } // complete Mammal // Using the object named 'spot', call the toString method and output the results System.out.printf( "%n\t\t%s", spot.toString( ) ); // Ask if the user wants to enter another Pet System.out.printf( "%n%nDo you wish to enter another Pet? (Yes or No)" ); response = input.next( ); // Test the user response if( response.equalsIgnoreCase( "No" ) ) again = false; } // end while loop // Let user know we are finished System.out.printf( "%n%n\t\t Thank you!" ); } // end main } // end TestPetHierarchy
JAVA PROGRAMS
Please find below the 3 classes that are used In the test harness class given (the given main class is not written here):
Pet class
package pet;
/**
class Pet
*
*/
public class Pet { //parent class
private String name;
private String owner;
private String birthday;
public Pet() {
//default constructor
}
//parametrized
public Pet(String name, String owner, String birthday)
{
this.name = name;
this.owner = owner;
this.birthday = birthday;
}
public final String getName() {
return name;
}
public final void setName(String aName) {
this.name = aName;
}
public final String getOwner() {
return owner;
}
public final void setOwner(String anOwner) {
this.owner = anOwner;
}
public final String getBirthday() {
return birthday;
}
public final void setBirthday(String aBDay) {
this.birthday = aBDay;
}
//parent's toString() method
@Override
public String toString() {
return this.name+ ", whose parent
is "+ this.owner+", was born on "+this.birthday+".";
}
}
Mammal class
package pet;
/**
class Mammal exends Pet
*
*/
public class Mammal extends Pet{
private String species;
private String vax;
//default
public Mammal(){
super();
}
//parametrized
public Mammal(String name, String owner, String
birthday,String species,String vax){
super(name,owner,birthday);
this.species = species;
this.vax = vax;
}
public String getSpecies() {
return species;
}
public void setSpecies(String aSpecies) {
this.species = aSpecies;
}
public String getVax() {
return vax;
}
public void setVax(String aDate) {
this.vax = aDate;
}
//overridden toString
@Override
public String toString() {
return super.toString()+ " The
Mammal is a(n) \n"+this.species+"."+ " Required vaccination date is
"+this.vax+".";
}
}
Reptile class
package pet;
//class Reptile extending Pet
public class Reptile extends Pet {
private String species;
private String enviro;
//default
public Reptile() {
super();
}
//parametrized
public Reptile(String name, String owner, String
birthday,String species,String enviro){
super(name,owner,birthday);
this.species=species;
this.enviro = enviro;
}
public final String getSpecies() {
return species;
}
public final void setSpecies(String aSpecies)
{
this.species = aSpecies;
}
public final String getEnviro() {
return enviro;
}
public final void setEnviro(String anEnviro)
{
this.enviro = anEnviro;
}
//overridden toString()
@Override
public String toString() {
return super.toString()+ " The
Reptile is \n"+this.species+". "+"Its required environment is
"+this.enviro;
}
}
OUTPUT
Please enter the pet's name:
Sugar
Please enter the pet's owner's name:
Gene
Please enter the pet's birthday in yyyy/mm/dd format:
2011/01/11
Is the pet a Mammal (1) or a Reptile (2)?
1
Please enter the Mammal's species:
dog
Please enter the date of next required vaccinations in yyyy/mm/dd
format:
2019/09/10
Sugar, whose parent is Gene, was
born on 2011/01/11. The Mammal is a(n)
dog. Required vaccination date is 2019/09/10.
Do you wish to enter another Pet? (Yes or No)yes
Please enter the pet's name:
Rosco
Please enter the pet's owner's name:
Bobby
Please enter the pet's birthday in yyyy/mm/dd format:
2012/03/12
Is the pet a Mammal (1) or a Reptile (2)?
2
Please enter the Reptile's species:
turtle
Please enter a description of the Reptile's required
environment:
damp,water
Rosco, whose parent is Bobby,
was born on 2012/03/12. The Reptile is
turtle. Its required environment is damp,water
Do you wish to enter another Pet? (Yes or No)no
Thank you!
Code in JAVA UML //TEST HARNESS //DO NOT CHANGE CODE FOR TEST HARNESS import java.util.Scanner; //...
public class Pet { //Declaring instance variables private String name; private String species; private String parent; private String birthday; //Zero argumented constructor public Pet() { } //Parameterized constructor public Pet(String name, String species, String parent, String birthday) { this.name = name; this.species = species; this.parent = parent; this.birthday = birthday; } // getters and setters public String getName() { return name; ...
Write a Java class named Employee to meet the requirements described in the UML Class Diagram below: Note: Code added in the toString cell are not usually included in a regular UML class diagram. This was added so you can understand what I expect from you. If your code compiles cleanly, is defined correctly and functions exactly as required, the expected output of your program will solve the following problem: “An IT company with four departments and a staff strength...
*PLEASE HELP ASAP* Pet.java /* * Class Pet * * * */ public class Pet { /* * Instance variables */ private String name; private String species; private String parent; private String birthday; /* * Constructors */ public Pet( ) { // This is a null or default constructor } //e end null constructor public Pet( String aName, String aSpecies, String aParent, String aBDay ) { setName( aName ); setSpecies( aSpecies ); setParent( aParent ); setBirthday( aBDay ); } //...
Write a Java class called BankAccount (Parts of the code is given below), which has two fields name (String) and balance (double), two constructors and five methods getName(), getBalance(), deposit (double amount), withdraw(double amount) and toString(). The first constructor should initialize name to null and balance to 0. The second constructor initializes name and balance to the parameters passed. deposit method deposits the amount to the account causing the current balance to increase, withdraw method withdraws the amount causing the...
Write a Java class called BankAccount (Parts of the code is given below), which has two fields name (String) and balance (double), two constructors and five methods getName(), getBalance(), deposit (double amount), withdraw(double amount) and toString(). The first constructor should initialize name to null and balance to 0. The second constructor initializes name and balance to the parameters passed. deposit method deposits the amount to the account causing the current balance to increase, withdraw method withdraws the amount causing the...
(JAVA) Use the Pet.java program from the original problem (down below) Compile it. Create a text file named pets10.txt with 10 pets (or use the one below). Store this file in the same folder as your “class” file(s). The format is the same format used in the original homework problem. Each line in the file should contain a pet name (String), a comma, a pet’s age (int) in years, another comma, and a pet’s weight (double) in pounds. Perform the...
Lab Assignment : In this lab, you are going to implement QueueADT interface that defines a queue. Then you are going to use the queue to store animals. 1. Write a LinkedQueue class that implements the QueueADT.java interface using links. 2. Textbook implementation uses a count variable to keep track of the elements in the queue. Don't use variable count in your implementation (points will be deducted if you use instance variable count). You may use a local integer variable...
JAVA /** * This class stores information about an instructor. */ public class Instructor { private String lastName, // Last name firstName, // First name officeNumber; // Office number /** * This constructor accepts arguments for the * last name, first name, and office number. */ public Instructor(String lname, String fname, String office) { lastName = lname; firstName = fname; officeNumber = office; } /** * The set method sets each field. */ public void set(String lname, String fname, String...
Language is Java, any help is appreciated. Thank you! WHERE TO START FROM: import java.util.ArrayList; //PartTest.java //package simple; public class PartTest { public static void main(String[] args) { ArrayList<ExpendablePart> system=new ArrayList<ExpendablePart>(); // creating Part Object Part part1 = new ExpendablePart("Last, First"); part1.setNumber("AX-34R"); part1.setNcage("MN34R"); part1.setNiin("ABCD-RF-WDE-KLJM"); // printing information System.out.println(part1.toString()); //Create a part2 object of class Part Part part2=new ConsumablePart("Widget, purple"); part2.setNumber("12345"); part2.setNcage("OU812"); part2.setNiin("1234-12-123-1234"); // printing information System.out.println(part2.toString()); //checking equality of two Part class objects if(part1.equals(part2)) System.out.println("part1 and...
I need help with this Mammal: public class Mammal extends Pet{ String Vaccination=""; public Mammal(String name, String parent, String species, String birthday, String Vaccination) { //Accessing the super class Constructor and setting the variables. super(name,parent,species, birthday); this.Vaccination=Vaccination; } // end Mammal public String getVaccination() { return Vaccination; } // end getVaccination public void setVaccination(String Vaccination) { this.Vaccination = Vaccination; } // end setVaccination @Override public String toString() { return super.toString()+". This Mammal requires following vaccinations "+ Vaccination; } // end...