Question

Problem 3 - The Doctor Registry (20 points) In this last problem, your task is to create a class that is going to represent a

Assume Doctor Class is Following:

class Doctor
{
private String fullName;
private String registryNumber;
private String specialty;
  
public Doctor(String fullName, String registryNumber, String specialty)
{
this.fullName = fullName;
this.registryNumber = registryNumber;
this.specialty = specialty;
}
  
public String getName()
{
return fullName;
}
  
public String getRegistryNumber()
{
return registryNumber;
}
  
public String getSpecialty()
{
return specialty;
}
  
public void setName(String fullName)
{
this.fullName = fullName;
}
  
public boolean equals(Doctor other)
{
if(registryNumber == other.registryNumber)
return true;
else
return false;
}
  
public String toString()
{
return "Dr. "+fullName+", Specialty: "+specialty;
}
  
}

Please answer in JAVA

0 0
Add a comment Improve this question Transcribed image text
Answer #1

DoctorRegistry Class Code:

package docterregistry;

public class DoctorRegistry {
        // Attributes
        private String province;
        private Doctor[] doctors;

        // to hold how many doctors in list
        private int index = 0;

        /*
         * Constructor that creates the DoctorRegistry object with maximum doctors in
         * list to maxDoctors and with given province
         */
        public DoctorRegistry(int maxDoctors, String province) {
                this.doctors = new Doctor[maxDoctors];
                this.province = province;
        }

        // Method to register doctor
        public boolean register(Doctor doctor) {
                // if already maximum doctors in list do not add
                if (index == doctors.length) {
                        return false;
                }
                // to hold doctor already in list or not
                boolean found = false;

                // checking for given doctor present in list
                // Look for each doctor in list
                for (int i = 0; i < index; i++) {
                        // extract current doctor
                        Doctor d = doctors[i];

                        // if current doctor is given doctor
                        if (d.equals(doctor)) {
                                // mark as true(found)
                                found = true;
                                // stop searching
                                break;
                        }
                }

                // if already in list do not add and return false
                if (found) {
                        return false;
                }
                // else add doctor in next empty position and return true
                else {
                        doctors[index++] = doctor;
                        return true;
                }
        }

        // Method to de-register doctor by taking registry number
        public boolean deRegister(String registryNumber) {
                // Look for all doctors
                for (int i = 0; i < index; i++) {
                        // if current doctor registry number is same as provided registry number
                        if (doctors[i].getRegistryNumber().equalsIgnoreCase(registryNumber)) {
                                // set the current position as null and return true
                                doctors[i] = null;
                                return true;
                        }
                }
                return false;
        }

        // Method to return registered doctors list
        public Doctor[] getDoctorList() {
                // create a new Doctor array to hold all registered Doctors
                Doctor[] list = new Doctor[index];

                // Look for all Doctors
                for (int i = 0; i < index; i++) {
                        list[i]=doctors[i];
                }

                // return the list
                return list;
        }
}

Image Of Code:

GEEF BO Oval } 1 package docterregistry; 2 public class Doctor Registry { 4 // Attributes 5 private String province; 6 privat

// else add doctor in next empty position and return true else { doctors[index++] = doctor; return true; ܢܟ } // Method to de

Add a comment
Know the answer?
Add Answer to:
Assume Doctor Class is Following: class Doctor { private String fullName; private String registryNumber; private String...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1) Given the following “BasicAccount” class #include <iostream> #include <string> class BasicAccount {    private:      ...

    1) Given the following “BasicAccount” class #include <iostream> #include <string> class BasicAccount {    private:       std::string m_username ;       std::string m_password ;    public:       BasicAccount(std::string username, std::string password)       {          m_username = username ;          m_password = password ;       }               virtual std::string toString()       {          return "USERNAME(" + m_username + ") PASSWORD(" + m_password + ")" ;       }          std::string getUserName()       {          return m_username ;       }      virtual...

  • import java.util.*; public class Movie {    private String movieName; private int numMinutes; private boolean isKidFriendly;...

    import java.util.*; public class Movie {    private String movieName; private int numMinutes; private boolean isKidFriendly; private int numCastMembers; private String[] castMembers;    // default constructor public Movie() { movieName = "Flick"; numMinutes = 0; isKidFriendly = false; numCastMembers = 0; castMembers = new String[10]; }    // overloaded parameterized constructor public Movie(String movieName, int numMinutes, boolean isKidFriendly, String[] castMembers) { this.movieName = movieName; this.numMinutes = numMinutes; this.isKidFriendly = isKidFriendly; numCastMembers = castMembers.length; this.castMembers = new String[numCastMembers];    for(int i=0;i<castMembers.length;i++)...

  • public class CylindricalTank {    private String idTag;           // Unique String identifying the tank...

    public class CylindricalTank {    private String idTag;           // Unique String identifying the tank    private double radius;           // The non-negative radius of the base of the tank in meters    private double height;           // The non-negative height of the tank in meters    private double liquidLevel;       // The current height of the liquid in the tank in meters    /**    * CylindricalTank General Constructor    */    public CylindricalTank(String tag, double...

  • public class Player { private String name; private int health; public Player(String name) { this.name =...

    public class Player { private String name; private int health; public Player(String name) { this.name = name; } } Write a complete method using java to find a Player by name in an array of Player objects. Use a linear search algorithm. The method should either return the first Player object with the requested name, or null if no player with that name is found.

  • HospitalEmployee Inheritance help please. import java.text.NumberFormat; public class HospitalEmployee {    private String empName;    private...

    HospitalEmployee Inheritance help please. import java.text.NumberFormat; public class HospitalEmployee {    private String empName;    private int empNumber;    private double hoursWorked;    private double payRate;       private static int hospitalEmployeeCount = 0;    //-----------------------------------------------------------------    // Sets up this hospital employee with default information.    //-----------------------------------------------------------------    public HospitalEmployee()    { empName = "Chris Smith"; empNumber = 9999; hoursWorked = 0; payRate =0;               hospitalEmployeeCount++;    }       //overloaded constructor.    public HospitalEmployee(String eName,...

  • JAVA /** * This class stores information about an instructor. */ public class Instructor { private...

    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...

  • Consider the following classes: class Box {     private bool isLidOpen;     public Box()     {         isLidOpen =...

    Consider the following classes: class Box {     private bool isLidOpen;     public Box()     {         isLidOpen = true;     }     public virtual void OpenLid()     {         isLidOpen = true;     }     public virtual void CloseLid()     {         isLidOpen = false;     } } class LockableBox : Box {     private bool isLidLocked;     public LockableBox()     {         isLidLocked = false;     }     public void LockLid()     {         isLidLocked = true;     }     public void UnlockLid()     {         isLidLocked = false;     }     public...

  • Consider the Automobile class: public class Automobile {    private String model;    private int rating;...

    Consider the Automobile class: public class Automobile {    private String model;    private int rating; // a number 1, 2, 3, 4, 5    private boolean isTruck;    public Automobile(String model, boolean isTruck) {       this.model = model;       this.rating = 0; // unrated       this.isTruck = isTruck;    }        public Automobile(String model, int rating, boolean isTruck) {       this.model = model;       this.rating = rating;       this.isTruck = isTruck;    }                public String getModel()...

  • / Animal.hpp #ifndef ANIMAL_H_ #define ANIMAL_H_ #include <string> class Animal { public: Animal(); Animal(std::string, bool domestic=false,...

    / Animal.hpp #ifndef ANIMAL_H_ #define ANIMAL_H_ #include <string> class Animal { public: Animal(); Animal(std::string, bool domestic=false, bool predator=false); std::string getName() const; bool isDomestic() const; bool isPredator() const; void setName(std::string); void setDomestic(); void setPredator(); protected: // protected so that derived class can directly access them std::string name_; bool domestic_; bool predator_; }; #endif /* ANIMAL_H_ */ //end of Animal.h // /////////////////////////////////////////////////////////////////Animal.cpp #include "Animal.h" Animal::Animal(): name_(""),domestic_(false), predator_(false){ } Animal::Animal(std::string name, bool domestic, bool predator): name_(name),domestic_(domestic), predator_(predator) { } std::string Animal::getName() const{ return...

  • Writing 3 Java Classes for Student registration /** * A class which maintains basic information about...

    Writing 3 Java Classes for Student registration /** * A class which maintains basic information about an academic course. */ public class Course {    /** * Attributes. */ private String code; private String title; private String dept; // name of department offering the course private int credits; /** * Constructor. */ public Course(String code, String title, int credits) { // TODO : initialize instance variables, use the static method defined in // Registrar to initialize the dept name variable...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT