Hello Im to the last of my assignment but Im having some iss
Hello. I\'m to the last of my assignment but I\'m having some issues getting the dates, and the doctor to print in the main class. Right now its throwing an error from me trying to change information in the main class of the object construction. Its due within 2 hours so a rapid response would be amazing. Can someone look at my code and fix it so the final information prints correctly? I\'d really appreciate it! Thank you!
TestHospital.java (main)
-------------
public class TestHospital {
public static void main(String[] args) {
Patient patient1 = new Patient(\"Robert\", \"Smith\", 1001, 42, \"Kenny\" + \"Rogers\", 8/12/1973, 10/20/2015,11/2/2015);
Bill bill1 = new Bill(1134.78, 1678.53, 3566.23, 1001);
System.out.print(patient1);
System.out.print(bill1);
System.out.println( );
Patient patient2 = new Patient(\"Bruno\", \"Mars\", 1002, 67, \"Barry\" + \"Gibb\", 1/25/1949,4/17/2015, 4/23/2015);
Bill bill2 = new Bill(954.8, 954.80, 765.54, 1002);
System.out.print(patient2);
System.out.print(bill2);
System.out.println( );
Patient patient3 = new Patient(\"Taylor\", \"Swift\", 1003, 5, \"Joshua\" + \"Bolan\", 10/11/2010, 7/2/2015,7/5/2015);
Bill bill3 = new Bill(1140.56, 689.54, 689.54, 1003);
System.out.print(patient3);
System.out.print(bill3);
System.out.println( );
Patient patient4 = new Patient(\"Kate\", \"Bush\", 1004, 53, \"Barry\" + \"Gibb\", 2/4/1963, 5/9/2015,5/16/2015);
Bill bill4 = new Bill(1389.67, 1208.7, 845.50, 1004);
System.out.print(patient4);
System.out.print(bill4);
System.out.println( );
Patient patient5 = new Patient(\"Lily\", \"Allen\", 1005, 25, \"Mick\" + \"Hucknall\", 9/5/2015, 12/2/2015,12/2/2015);
Bill bill5 = new Bill(356.78, 150.80, 0, 1005);
System.out.print(patient5);
System.out.print(bill5);
}
}
-------------
Person.java
---------------
private String lastName;
private String firstName;
public Person(String last, String first)
{
this.lastName = last;
this.firstName = first;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String toString()
{
return firstName + \" \" + lastName;
}
}
-------------
Patient.java
------------
public class Patient extends Person{
private int PatientId;
private int age;
private Doctor Doctor;
private Date dob;
Date admitted;
private Date discharged;
public Patient(String firstName,String lastName,int PatientId,int age,String Doctor,Date dob,Date admitted,Date discharged)
{
super(lastName,firstName);
this.PatientId = PatientId;
this.age = age;
this.admitted = admitted;
this.discharged = discharged;
this.dob = dob;
// this.attendingPhysician = new Doctor(firstName, lastName, Speciality);
}
public int getPatientId()
{
return PatientId;
}
public int getAge()
{
return age;
}
public Date getAdmissionDate()
{
return admitted;
}
public Date getDischargedDate()
{
return discharged;
}
public Date getDOB()
{
return dob;
}
public Doctor getPhysician()
{
return Doctor;
}
public void setPatientId(int PatientId)
{
this.PatientId = PatientId;
}
public void setAge(int age)
{
this.age = age;
}
public void setAdmissionDate(Date admitted)
{
this.admitted = admitted;
}
public void setDischargedDate(Date discharged)
{
this.discharged = discharged;
}
public void setDOB(Date dob)
{
this.dob = dob;
}
public void setPhysician(Doctor Doctor)
{
this.Doctor = Doctor;
}
public String toString(){
String str = \"Your name, date of birth and age are \" + super.toString() + \", \" + dob + \", \" + this.age + \"\ \" +
\"Your ID is \" + this.PatientId + \". Your doctor is \" + Doctor +\".\" + \"\ \"
+ \"Your admit date is \" + admitted + \" and you left at \" + discharged + \". \ \";
return str;
}
}
-----------------
Doctor.java
-----------
public class Doctor extends Person { // doctor class that inherits the person
// class
String Speciality;
String firstName;
String lastName;
public Doctor(String first, String last, String Speciality) { // constructor
super(first, last);
this.firstName = firstName;
this.lastName = lastName;
this.Speciality = Speciality;
}
public String getfirstName() {
return firstName;
}
public String getlastName() {
return lastName;
}
public String getSpeciality() {
return Speciality;
}
public void setfirstName() {
this.firstName = firstName;
}
public void setlastName() {
this.lastName = lastName;
}
public void setSpeciality(String Speciality) {
this.Speciality = Speciality;
}
public String toString() { // method that return the data of the doctor
return firstName + lastName + \"(\" + Speciality + \")\";
}
}
------------------
Date.java
-------------
public class Date {
private int year;
private int month;
private int day;
public Date()
{
year = 1900;
month = 1;
day = 1;
}
public Date(int y, int m, int d)
{
year = y;
month = m;
day = d;
}
public String toString()
{
return month + \"/\" + day + \"/\" + year;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public int getMonth() {
return month;
}
public void setMonth(int month) {
this.month = month;
}
public int getDay() {
return day;
}
public void setDay(int day) {
this.day = day;
}
}
----------
Bill.java
-----------
public class Bill {
private double doctorFee, pharmacyCharge, roomCharge;
private int patientId;
private double billSum;
public Bill() {
}
public Bill(double doctorFee, double pharmacyCharge, double roomCharge, int patientId) {
this.doctorFee = doctorFee;
this.pharmacyCharge = pharmacyCharge;
this.roomCharge = roomCharge;
this.patientId = patientId;
}
public double getDoctorFee() {
return doctorFee;
}
public double getpharmacyCharge() {
return pharmacyCharge;
}
public double getRoomCharge() {
return roomCharge;
}
public int getPatientId() {
return patientId;
}
public void setDoctorFee(double doctorFee) {
this.doctorFee = doctorFee;
}
public void setpharmacyCharge(double pharmacyCharge) {
this.pharmacyCharge = pharmacyCharge;
}
public void setRoomCharge(double roomCharge) {
this.roomCharge = roomCharge;
}
public void setPatientId(int patientId) {
this.patientId = patientId;
}
public double calcBillSum() {
this.billSum = this.doctorFee + this.pharmacyCharge + this.roomCharge;
return this.billSum;
}
public String toString() {
String billStr = \"Thank you, your patient ID is \" + this.patientId + \", and your total bill is $\"
+ this.calcBillSum() + \"\ \";
return billStr;
}
}
-------------
Current output:
Your name, date of birth and age are Robert Smith, 0, 42
Your ID is 1001. Your doctor is null.
Your admit date is 0 and you left at 0.
Thank you, your patient ID is 1001, and your total bill is $6379.54
Your name, date of birth and age are Bruno Mars, 0, 67
Your ID is 1002. Your doctor is null.
Your admit date is 0 and you left at 0.
Thank you, your patient ID is 1002, and your total bill is $2675.14
Your name, date of birth and age are Taylor Swift, 0, 5
Your ID is 1003. Your doctor is null.
Your admit date is 0 and you left at 0.
Thank you, your patient ID is 1003, and your total bill is $2519.64
Your name, date of birth and age are Kate Bush, 0, 53
Your ID is 1004. Your doctor is null.
Your admit date is 0 and you left at 0.
Thank you, your patient ID is 1004, and your total bill is $3443.87
Your name, date of birth and age are Lily Allen, 0, 25
Your ID is 1005. Your doctor is null.
Your admit date is 0 and you left at 0.
Thank you, your patient ID is 1005, and your total bill is $507.58
There shouldn\'t be any 0\'s, and where the doctor is null, it should say the doctor\'s first name followed by last name and then their specialty. So for the first one it should say \"your doctor is Kenny Rogers (Neurological Surgery).
The other doctors are
Mick Huckal (Dermatology)
Barry Gibb (Cardiovascular Disease)
Joshua Bolan (Pediatrics)
Solution
Hi, You are calling the patient constructor with new Patient(\"Robert\", \"Smith\", 1001, 42, \"Kenny\" + \"Rogers\", 8/12/1973, 10/20/2015,11/2/2015); and you defined your patient constructor some thing like public Patient(String firstName,String lastName,int PatientId,int age,String Doctor,Date dob,Date admitted,Date discharged). As 8/12/1973 is considered as a mathematical equation and it evaluates to 0 in integer hence dob and other dates are 0. On the other hand the doctor constrouctor was never called. Hence you were getting wrong output.
I have modified your code for correctness and also i had removed unnecessary getter setter functions in the code. Please find the code as below:
TestHospital.java
-----------------------
public class TestHospital {
public static void main(String[] args) {
//Doctor counstructor call (name,last,speciality)
//Date Constructor call (year,month,date)
Patient patient1 = new Patient(\"Robert\", \"Smith\", 1001, 42, new Doctor(\"Kenny\", \"Rogers\",\"Neurological Surgery\"), new Date(1973,8,12), new Date(2015,10,20), new Date(2015,11,2));
Bill bill1 = new Bill(1134.78, 1678.53, 3566.23, 1001);
System.out.print(patient1);
System.out.print(bill1);
System.out.println( );
Patient patient2 = new Patient(\"Bruno\", \"Mars\", 1002, 67, new Doctor(\"Barry\", \"Gibb\",\"Cardiovascular Disease\"), new Date(1949,1,25),new Date(2015,4,17), new Date(2015,4,23));
Bill bill2 = new Bill(954.8, 954.80, 765.54, 1002);
System.out.print(patient2);
System.out.print(bill2);
System.out.println( );
Patient patient3 = new Patient(\"Taylor\", \"Swift\", 1003, 5, new Doctor(\"Joshua\", \"Bolan\", \"Pediatrics\"), new Date(2010,10,11), new Date(2015,7,2), new Date(2015,7,5));
Bill bill3 = new Bill(1140.56, 689.54, 689.54, 1003);
System.out.print(patient3);
System.out.print(bill3);
System.out.println( );
Patient patient4 = new Patient(\"Kate\", \"Bush\", 1004, 53, new Doctor(\"Barry\", \"Gibb\",\"Cardiovascular Disease\"), new Date(1963,2,4), new Date(2015,5,9), new Date(2015,5,16));
Bill bill4 = new Bill(1389.67, 1208.7, 845.50, 1004);
System.out.print(patient4);
System.out.print(bill4);
System.out.println( );
Patient patient5 = new Patient(\"Lily\", \"Allen\", 1005, 25, new Doctor(\"Mick\",\"Hucknall\",\"Dermatology\"), new Date(2015,9,5), new Date(2015,12,2), new Date (2015,12,2));
Bill bill5 = new Bill(356.78, 150.80, 0, 1005);
System.out.print(patient5);
System.out.print(bill5);
}
}
Person.java
-----------------
public class Person {
private String lastName;
private String firstName;
public Person(String last, String first) {
this.lastName = last;
this.firstName = first;
}
public String toString() {
return firstName + \" \" + lastName;
}
}
Patient.java
------------------
public class Patient extends Person{
private int PatientId;
private int age;
private Doctor Doctor;
private Date dob;
Date admitted;
private Date discharged;
public Patient(String firstName,String lastName,int PatientId,int age,Doctor Doctor,Date dob,Date admitted,Date discharged)
{
super(lastName,firstName);
this.PatientId = PatientId;
this.age = age;
this.admitted = admitted;
this.discharged = discharged;
this.dob = dob;
this.Doctor = Doctor;
}
public String toString(){
String str = \"Your name, date of birth and age are \" + super.toString() + \", \" + dob + \", \" + this.age + \"\ \" +
\"Your ID is \" + this.PatientId + \". Your doctor is \" + Doctor +\".\" + \"\ \"
+ \"Your admit date is \" + admitted + \" and you left at \" + discharged + \". \ \";
return str;
}
}
Doctor.java
------------------
public class Doctor extends Person { // doctor class that inherits the person
// class
String Speciality;
String firstName;
String lastName;
public Doctor(String first, String last, String Speciality) { // constructor
super(first, last);
this.firstName = first;
this.lastName = last;
this.Speciality = Speciality;
}
public String toString() { // method that return the data of the doctor
return firstName + lastName + \"(\" + Speciality + \")\";
}
}
Date.java
---------------
public class Date {
private int year;
private int month;
private int day;
public Date()
{
year = 1900;
month = 1;
day = 1;
}
public Date(int y, int m, int d)
{
year = y;
month = m;
day = d;
}
public String toString()
{
return month + \"/\" + day + \"/\" + year;
}
}
Bill.java
------------
public class Bill {
private double doctorFee, pharmacyCharge, roomCharge;
private int patientId;
private double billSum;
public Bill() {
}
public Bill(double doctorFee, double pharmacyCharge, double roomCharge, int patientId) {
this.doctorFee = doctorFee;
this.pharmacyCharge = pharmacyCharge;
this.roomCharge = roomCharge;
this.patientId = patientId;
}
public double calcBillSum() {
this.billSum = this.doctorFee + this.pharmacyCharge + this.roomCharge;
return this.billSum;
}
public String toString() {
String billStr = \"Thank you, your patient ID is \" + this.patientId + \", and your total bill is $\"
+ this.calcBillSum() + \"\ \";
return billStr;
}
}
All the best









