Give the definition of a class named doctor

Assignment Help JAVA Programming
Reference no: EM13941186

Give the definition of a class named Doctor whose objects are records for a clinic's doctors. This class will be a derived class of the class SalariedEmployee given in Display 7.5. A Doctor record has the doctor's specialty (such as "Pediatrician", "Obstetrician", "General Practitioner", and so forth; so use the type String), and office visit fee (use type double). Be sure your class has a reasonable complement of constructors, accessor and mutator methods, and suitably defined equals, and toString methods. Write a program to test all your methods.

You should implement the following methods:

public Doctor()
public Doctor(String theName, Date theDate, double theSalary,
String theSpecialty, double theVisitFee)
public Doctor(Doctor orig)
public String getSpecialty()
public void setSpecialty(String theSpecialty)
public double getVisitFee()
public void setVisitFee(double theVisitFee)
public boolean equals(Doctor other)

HINT:

Constructors defined in the Doctor class can call the superclass's constructor (e.g. super(theName, theDate, theSalary)) nto initialize the instance variables in SalariedEmployee.
By subclassing SalariedEmployee, the Doctor class will inherit not only the methods defined in SalariedEmployee, but also those defined in Employee. You may override (re-implement) methods in the Employee class, but in this project you need only override the toString and equals methods.
Make sure that you initialize the specialty and visitFee fields in your zero-argument constructor.

/**
Subclass of SalariedEmployee that adds specicialty and visit fee fields.
*/
class Doctor extends SalariedEmployee {
/**
The doctor's specialty
*/
private String specialty;

/**
The doctor's visit fee
*/
private double visitFee;

// --------------------------------
// ----- ENTER YOUR CODE HERE -----
// --------------------------------

// --------------------------------
// --------- END USER CODE --------
// --------------------------------

public String toString() {
// Adapted from SalariedEmployee.toString()
return getName() + " (Specialty: " +
getSpecialty() + ")" + "n Fee for office visit: " +
getVisitFee() + "n Hired " + getHireDate() +
", tiny_mce_markerquot; + getSalary() + " per year";
}

}

/**
Demo program that tests the methods of the Doctor class
*/
public class DoctorDemo {

public static void main(String[] args) {
// Test the constructors
Doctor doc = new Doctor();
System.out.println("Doctor created without arguments:");
System.out.println(doc);
System.out.println();

Doctor pediatrician = new Doctor("Dr. John Doe",
new Date("March", 15, 2001), 123500.00,
"Pediatrics", 125.00);
System.out.println("Doctor created with all arguments:");
System.out.println(pediatrician);
System.out.println();

// Test the copy constructor and equals method
Doctor p2 = new Doctor(pediatrician);
System.out.println("Doctor created with copy constructor:");
System.out.println(p2);
System.out.println();
System.out.println("pediatrician == p2? " + (pediatrician == p2));
System.out.println(
"pediatrician.equals(p2)? " + pediatrician.equals(p2));
System.out.println(
"pediatrician.equals(doc)? " + pediatrician.equals(p2));
System.out.println();

// Test the setter and getter methods
p2.setName("Dr. Joe Smith");
p2.setSpecialty("Opthomology");
p2.setVisitFee(110.0);
System.out.println(
"After resetting name, specialty, and office visit fee:");
System.out.println(p2);
System.out.println();
System.out.println("Specialty: " + p2.getSpecialty());
System.out.println("OfficeVisitFee: tiny_mce_markerquot; + p2.getVisitFee());
System.out.println();

}

}

Employee.java

/**
Class Invariant: All objects have a name string and hire date.
A name string of "No name" indicates no real name specified yet.
A hire date of Jan 1, 1000 indicates no real hire date specified yet.
*/
public class Employee
{
private String name;
private Date hireDate;

public Employee( )
{
name = "No name";
hireDate = new Date("January", 1, 1000); //Just a place holder.
}

/**
Precondition: Neither theName nor theDate are null.
*/
public Employee(String theName, Date theDate)
{
if (theName == null || theDate == null)
{
System.out.println("Fatal Error creating employee.");
System.exit(0);
}
name = theName;
hireDate = new Date(theDate);
}

public Employee(Employee originalObject)
{
name = originalObject.name;
hireDate = new Date(originalObject.hireDate);
}

public String getName( )
{
return name;
}

public Date getHireDate( )
{
return new Date(hireDate);
}

/**
Precondition newName is not null.
*/
public void setName(String newName)
{
if (newName == null)
{
System.out.println("Fatal Error setting employee name.");
System.exit(0);
}
else
name = newName;
}

/**
Precondition newDate is not null.
*/
public void setHireDate(Date newDate)
{
if (newDate == null)
{
System.out.println("Fatal Error setting employee hire date.");
System.exit(0);
}
else
hireDate = new Date(newDate);
}

public String toString( )
{
return (name + " " + hireDate.toString( ));
}

public boolean equals(Employee otherEmployee)
{
return (name.equals(otherEmployee.name)
&& hireDate.equals(otherEmployee.hireDate));
}
}

SalariedEmploye.java

/**
Class Invariant: All objects have a name string, hire date, and nonnegative salary.
A name string of "No name" indicates no real name specified yet.
A hire date of Jan 1, 1000 indicates no real hire date specified yet.
*/
public class SalariedEmployee extends Employee
{
private double salary; //annual

public SalariedEmployee( )
{
super( );
salary = 0;
}

/**
Precondition: Neither theName nor theDate are null;
theSalary is nonnegative.
*/
public SalariedEmployee(String theName, Date theDate, double theSalary)
{
super(theName, theDate);
if (theSalary >= 0)
salary = theSalary;
else
{
System.out.println("Fatal Error: Negative salary.");
System.exit(0);
}
}

public SalariedEmployee(SalariedEmployee originalObject )
{
super(originalObject);
salary = originalObject.salary;
}
public double getSalary( )
{
return salary;
}

/**
Returns the pay for the month.
*/
public double getPay( )
{
return salary/12;
}

/**
Precondition: newSalary is nonnegative.
*/
public void setSalary(double newSalary)
{
if (newSalary >= 0)
salary = newSalary;
else
{
System.out.println("Fatal Error: Negative salary.");
System.exit(0);
}
}

public String toString( )
{
return (getName( ) + " " + getHireDate( ).toString( )
+ "ntiny_mce_markerquot; + salary + " per year");
}

public boolean equals(SalariedEmployee other)
{
return (getName( ).equals(other.getName( ))
&& getHireDate( ).equals(other.getHireDate( ))
&& salary == other.salary);
}
}

Date.java

import java.util.Scanner;

public class Date
{
private String month;
private int day;
private int year; //a four digit number.

public Date( )
{
month = "January";
day = 1;
year = 1000;
}

public Date(int monthInt, int day, int year)
{
setDate(monthInt, day, year);
}

public Date(String monthString, int day, int year)
{
setDate(monthString, day, year);
}

public Date(int year)
{
setDate(1, 1, year);
}

public Date(Date aDate)
{
if (aDate == null)//Not a real date.
{
System.out.println("Fatal Error.");
System.exit(0);
}

month = aDate.month;
day = aDate.day;
year = aDate.year;
}

public void setDate(int monthInt, int day, int year)
{
if (dateOK(monthInt, day, year))
{
this.month = monthString(monthInt);
this.day = day;
this.year = year;
}
else
{
System.out.println("Fatal Error");
System.exit(0);
}
}

public void setDate(String monthString, int day, int year)
{
if (dateOK(monthString, day, year))
{
this.month = monthString;
this.day = day;
this.year = year;
}
else
{
System.out.println("Fatal Error");
System.exit(0);
}
}

public void setDate(int year)
{
setDate(1, 1, year);
}

public void setYear(int year)
{
if ( (year < 1000) || (year > 9999) )
{
System.out.println("Fatal Error");
System.exit(0);
}
else
this.year = year;
}
public void setMonth(int monthNumber)
{
if ((monthNumber <= 0) || (monthNumber > 12))
{
System.out.println("Fatal Error");
System.exit(0);
}
else
month = monthString(monthNumber);
}

public void setDay(int day)
{
if ((day <= 0) || (day > 31))
{
System.out.println("Fatal Error");
System.exit(0);
}
else
this.day = day;
}

public int getMonth( )
{
if (month.equals("January"))
return 1;
else if (month.equals("February"))
return 2;
else if (month.equalsIgnoreCase("March"))
return 3;
else if (month.equalsIgnoreCase("April"))
return 4;
else if (month.equalsIgnoreCase("May"))
return 5;
else if (month.equals("June"))
return 6;
else if (month.equalsIgnoreCase("July"))
return 7;
else if (month.equalsIgnoreCase("August"))
return 8;
else if (month.equalsIgnoreCase("September"))
return 9;
else if (month.equalsIgnoreCase("October"))
return 10;
else if (month.equals("November"))
return 11;
else if (month.equals("December"))
return 12;
else
{
System.out.println("Fatal Error");
System.exit(0);
return 0; //Needed to keep the compiler happy
}
}

public int getDay( )
{
return day;
}

public int getYear( )
{
return year;
}

public String toString( )
{
return (month + " " + day + ", " + year);
}

public boolean equals(Date otherDate)
{
if (otherDate == null)
return false;
else
return ( (month.equals(otherDate.month)) &&
(day == otherDate.day) && (year == otherDate.year) );
}

public boolean precedes(Date otherDate)
{
return ( (year < otherDate.year) ||
(year == otherDate.year && getMonth( ) < otherDate.getMonth( )) ||
(year == otherDate.year && month.equals(otherDate.month)
&& day < otherDate.day) );
}

public void readInput( )
{
boolean tryAgain = true;
Scanner keyboard = new Scanner(System.in);
while (tryAgain)
{
System.out.println("Enter month, day, and year.");
System.out.println("Do not use a comma.");
String monthInput = keyboard.next( );
int dayInput = keyboard.nextInt( );
int yearInput = keyboard.nextInt( );
if (dateOK(monthInput, dayInput, yearInput) )
{
setDate(monthInput, dayInput, yearInput);
tryAgain = false;
}
else
System.out.println("Illegal date. Reenter input.");
}
}

private boolean dateOK(int monthInt, int dayInt, int yearInt)
{
return ( (monthInt >= 1) && (monthInt <= 12) &&
(dayInt >= 1) && (dayInt <= 31) &&
(yearInt >= 1000) && (yearInt <= 9999) );
}

private boolean dateOK(String monthString, int dayInt, int yearInt)
{
return ( monthOK(monthString) &&
(dayInt >= 1) && (dayInt <= 31) &&
(yearInt >= 1000) && (yearInt <= 9999) );
}

private boolean monthOK(String month)
{
return (month.equals("January") || month.equals("February") ||
month.equals("March") || month.equals("April") ||
month.equals("May") || month.equals("June") ||
month.equals("July") || month.equals("August") ||
month.equals("September") || month.equals("October") ||
month.equals("November") || month.equals("December") );
}

private String monthString(int monthNumber)
{
switch (monthNumber)
{
case 1:
return "January";
case 2:
return "February";
case 3:
return "March";
case 4:
return "April";
case 5:
return "May";
case 6:
return "June";
case 7:
return "July";
case 8:
return "August";
case 9:
return "September";
case 10:
return "October";
case 11:
return "November";
case 12:
return "December";
default:
System.out.println("Fatal Error");
System.exit(0);
return "Error"; //to keep the compiler happy
}
}

Reference no: EM13941186

Questions Cloud

Bunn operates a small family bakery : It has recently moved into new premises and has invested in more advanced equipment, with the aim of making the baking process more automated.
Assuming that purchasing-power parity holds : A McDonald’s Big Mac costs 2.44 yuan in China, but costs $4.20 in the United States. Assuming that purchasing-power parity (PPP) holds, how many Chinese yuan are required to purchase 1 U.S. dollar?
Developing and staging events in a region : "It is important to develop a strategic and co-ordinated approach to developing and staging events in a region. A strategic approach should address issues such as the proliferation of events, consistency with regional branding, managing growing at..
Income in the current year and save it for retirement : A consumer has decided to set aside $2000 out of her income in the current year and save it for retirement. She has the choice of putting all $2000 in a traditional IRA or else putting all $2000 in a Roth IRA. you may assume that she knows her margin..
Give the definition of a class named doctor : Give the definition of a class named Doctor whose objects are records for a clinic's doctors.
Developed a new innovative product : A young entrepreneur who has developed a new innovative product has been invited to pitch on the BBC TV programme 'Dragons Den'. The product is called 'Boot Magic' and is designed to clean football boots without the inside of the boot getting wet...
Issue new stock to finance its capital budget : Assume that you are on the financial staff of Vanderheiden Inc., and you have collected the following data: The yield on the company's outstanding bonds is 7.75%, its tax rate is 40%, the next expected dividend is $0.65 a share, What is the firm's WA..
What factors impact the dividend policy decision : Assume your firm has never distributed cash to its shareholders. However, now you are trying to determine the appropriate way to distribute some cash that is consistent with maximizing shareholder wealth. Why would a dividend distribution be importan..
Why hrm is important in todays business environment : Define Human Resource Management (HRM). Explain why HRM is important in today's business environment.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a java application to display the following gui

Write a Java application to display the following GUI. At this point you are only implementing the display. We are not ready to make the calculator actually do any calculations

  Method to calculate all primes in the range [2..n]

One commonly used method to calculate all primes in the range [2..n] is to start with the number 2, mark it as prime, and mark all its multiples (excluding itself) as not prime. Then, we find the next smallest unmarked number, mark it as prime, and m..

  How to read data in a link list

How to read data in a link list?

  Write the java code for an abstract class named account

Write the Java code for an abstract class named Account which has two data members; one for the account number and the other for the account balance (use information hiding). The Account class should include get and set methods for both data membe..

  Write a java program to simulate a die

Write a Java program to simulate a die. A die has values of either 1, 2, 3, 4, 5 or 6 on the face. You should use the Math.Random() or the java.util.Random() class to generate the values on the die.

  Write the classic arcade game of breakout

For each instance variable in your program, explain why you chose to make it an instance variable rather than a local variable - How did you test whether the game would end correctly in this second case? Did you make any changes to the code when test..

  Java socket hello i need to this assignment done in net

hello i need to this assignment done in net beans . and i want comment in code .also screen shots of running program

  Setting up the form page

Download and save the attached comment CGI mailer script form-mail2.pl to your server's cgi-bin directory, and change the permissions on the script to make it executable (not writable).

  Javas drawing capabilities

This week, we will be learning to use some of Java's drawing capabilities. The Graphics class provides methods for drawing many different shapes, using different colors, and for drawing strings using different fonts.

  Modify the inventory program by adding a button to the gui

If the first item is displayed and the user clicks on the Previous button, the last item should display. If the last item is displayed and the user clicks on the Next button, the first item should display. Add a company logo to the GUI using Java ..

  Statements to print a label

Add the statements to print a label in the following format (the numbers in the example output are correct for input of $4.25 per pound and 41 ounces). Use the formatting object money to print the unit price and total price and the formatting object ..

  Calculates the letter grade the student has earned

It then calculates the letter grade the student has earned, based on the average score of these assignments.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd