outprintlnAfter changing just one character in the social security number

Outprintlnafter changing just one character in the

This preview shows page 32 - 36 out of 42 pages.

System.out.println("After changing just one character" + " in the social security number,"); System.out.println("the data for the 2 partients are"); System.out.println(); System.out.println("First patient:"); p1.writeOutput(); System.out.println(); System.out.println("Second patient:"); p4.writeOutput(); System.out.println(); System.out.println("Verify: false."); System.out.println(); System.out.println(p1.equals(p4)); System.out.println(); System.out.println("Do again? (Y for Yes, or N for No)"); repeat = keyboard.next().charAt(0); }while((repeat == 'y') || (repeat == 'Y')); } }
Image of page 32
CSJA1DP/203/0/2016 33 File name: Billing.java - Class for a billing record for an office visit by a patient to see a doctor. Contains the name of the doctor, the name of the patient, and the doctor's fee for the office visit. public class Billing { private String aDoctor; private String aPatient; private double billingAmount; // Constructors: must have both a doctor and a patient. public Billing(Doctor theDoctor, Patient thePatient) { aDoctor = theDoctor.getName(); aPatient = thePatint.getName(); billingAmount = theDoctor.getOfficeFee(); } // Methods to display instance variable values. // Write all values public void writeOutput() { writeDoctorName(); writePatientName(); writeBillingAmount(); } public void writeDoctorName() { System.out.println("Doctor: " + aDoctor); } public void writePatientName() { System.out.println("Patient: " + aPatient); } public void writeBillingAmount() { System.out.println("Billing Amount: $" + billingAmount); } // Methods to change values of instance variables // Change all values public void set (String newDoctorName, String newPatientName, double newBillingAmount) { setDoctor(newDoctorName); setPatient(newPatientName); setBillingAmount(newBillingAmount); } public void setDoctor(String newDoctor) { aDoctor = newDoctor;
Image of page 33
34 } public void setPatient(String newPatient) { aPatient = newPatient; } public void setBillingAmount(double newBillingAmount) { billingAmount = newBillingAmount; } // Methods to return values of instance variables. public String getDoctor() { return aDoctor; } public String getPatient() { return aPatient; } public double getBillingAmount() { return billingAmount; } // Equals method public boolean equals(Billing otherBilling) { return this.aDoctor.equalsIgnoreCase(otherBilling.getDoctor()) && this.aPatient.equalsIgnoreCase(otherBilling.getPatient()) && this.billingAmount == otherBilling.billingAmount; } } File name: BillingTest.java - This program tests Billing class. import java.util.*; public class BillingTest { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); char repeat; do // repeat if user says 'yes' { // Test the constructor (uses writeOutput method) Doctor d1 = new Doctor("Spock", 200.00, "Pediatrician"); Doctor d2 = new Doctor("Dolittle", 175.00, "Witch"); Patient p1 = new Patient("Calvin", "123-45-6789"); Patient p2 = new Patient("Hobbes", "987-65-4321"); System.out.println(); System.out.println("Two doctors created:"); System.out.println();
Image of page 34
CSJA1DP/203/0/2016 35 d1.writeOutput(); System.out.println(); d2.writeOutput(); System.out.println(); System.out.println("Two patients created:"); System.out.println(); p1.writeOutput(); System.out.println(); p2.writeOutput(); System.out.println(); Billing b1 = new Billing(d1, p1); Billing b2 = new Billing(d1, p2); Billing b3 = new Billing(d2, p1); System.out.println("Three billing records created:");
Image of page 35
Image of page 36

You've reached the end of your free preview.

Want to read all 42 pages?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture