Instructions
Objective
Write a program to create a vet clinic system in java language.
Requirements and Specifications
VET CLINIC SYSTEM
- DATABASE MANAGEMENT SYSTEM
- METHODS
- INHERITANCE
- OOPS IMPLEMENTATION
- FUNCTIONS
Source Code
public class VetClinic {
private static final int COLLECTION_SIZE = 5;
private Vet[] vets = new Vet[COLLECTION_SIZE];
/* ---------------------------------------------------
--- Create a new VetClinic collection populated ---
--- with blank Vet entries ---
---------------------------------------------------
*/
public VetClinic() {
for (int i = 0; i < COLLECTION_SIZE; i++) {
this.vets[i] = new Vet();
}
}
/* ----------------------------------------------------
--- Display the entire VetClinic collection with ---
--- one vet per line. Empty entries should not ---
--- be printed. ---
----------------------------------------------------
*/
public void showVetClinic() {
System.out.println("\nMy VetClinic\n-----------------");
for (int i = 0; i < this.vets.length; i++) {
if (!this.vets[i].getName().equals(""))
System.out.println(this.vets[i]);
}
System.out.println("-----------------\n");
}
/* -----------------------------------------------
--- Add the newVet to the first element in ---
--- vets with name = "". Return true if ---
--- successful, false otherwise ---
-----------------------------------------------
*/
public boolean addVet(Vet newVet) {
// TO DO: Add code to this method to prevent the same name
// being used twice.
// If the name already exists in the collection,
// false is returned and the collection is not updated
int i = 0;
while (i < COLLECTION_SIZE && !this.vets[i].getName().equals("")) {
if (this.vets[i].getName().equals(newVet.getName())) {
return false;
}
i++;
}
if (i < COLLECTION_SIZE) {
this.vets[i] = newVet;
return true;
} else return false;
}
/* -----------------------------------------------------------
--- Update the specialism of the VetClinic item that ---
--- matches the name and specialism values of the Vet ---
--- passed as a parameter. Return true if successful or ---
--- false if a matching vet is not found. ---
-----------------------------------------------------------
*/
public boolean updateSpecialism(Vet aVet, String newSpecialism) {
// TO DO: Provide this method body
for (int i = 0; i < this.vets.length; i++) {
String name = this.vets[i].getName();
if (name.isEmpty()) {
continue;
}
if (name.equals(aVet.getName())) {
this.vets[i].setSpecialism(newSpecialism);
return true;
}
}
return false;
}
/* ----------------------------------------------------------
--- Return the vet names where the vet specialism ---
--- matches that passed as a parameter, one title per ---
--- or "" if the artist name is not found ---
----------------------------------------------------------
*/
public String getVetsBySpecialism(String aSpecialism) {
// TO DO: Provide this method body
StringBuilder builder = new StringBuilder("");
for (int i = 0; i < this.vets.length; i++) {
String name = this.vets[i].getName();
if (name.isEmpty()) {
continue;
}
if (this.vets[i].getSpecialism().equals(aSpecialism)) {
if (!builder.toString().isEmpty()) {
builder.append(System.lineSeparator());
}
builder.append(name);
}
}
return builder.toString();
}
/* ---------------------------------------------------------
--- Delete the Vet matching the name and specialism ---
--- of that passed as a parameter by setting it to an ---
--- empty Vet. Return true if successful or false if ---
--- the details in the parameter do not match a Vet ---
--- in the collection ---
---------------------------------------------------------
*/
public boolean delete(Vet aVet) {
// TO DO: Provide this method body
for (int i = 0; i < this.vets.length; i++) {
String name = this.vets[i].getName();
if (name.isEmpty()) {
continue;
}
if (this.vets[i].getName().equals(aVet.getName())) {
this.vets[i] = new Vet();
return true;
}
}
return false;
}
/* ------------------------------------------------------------
--- Return true if the VetClinic contains at least three ---
--- non-empty Vet objects or false otherwise ---
------------------------------------------------------------
*/
public boolean isViable() {
// TO DO: Provide this method body
int counter = 0;
for (int i = 0; i < this.vets.length; i++) {
String name = this.vets[i].getName();
if (name.isEmpty()) {
continue;
}
counter++;
}
return counter >= 3;
}
}