import java.util.Scanner; public class PatientDemo { public static void main(Str
ID: 3832512 • Letter: I
Question
import java.util.Scanner;
public class PatientDemo
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
char repeat;
do
{
//Test the constructors (uses writeOutput method)
Patient p1 = new Patient();
System.out.println("=========================");
System.out.println("Test constructor with just name:");
Patient p2 = new Patient("English");
System.out.println("=========================");
System.out.println("test constructor with both name and SSn:");
Patient p3 = new Patient("Yosarian", "777-77-7777");
System.out.println("=========================");
//Test methods to change, return and write values
//change all
System.out.println("Test to change name & SSN:");
System.out.println();
System.out.println("Before:");
p1.set(------, "------------");
System.out.println("Name:------");
System.out.println("SSN: --------");
System.out.println("After");
System.out.println("=========================");
System.out.println("Test to change name:");
System.out.println("=========================");
System.out.println("Test to change SSN:");
System.out.println("=========================");
System.out.println("Test to return name:");
System.out.println("=========================");
System.out.println("=========================");
System.out.println();
System.out.println();
System.out.println("First equals test:");
System.out.println();
//Create 2nd Patient with same insurance values
Patient p4 = new Patient("Faith", "222-22-2222");
System.out.println();
System.out.println("First patient's values:");
return p3;
System.out.println("Second patient's values:");
return p4;
System.out.println("=========================");
System.out.println("Do again? (Y for Yes, or N for No)");
repeat = keyboards.next().charAt(0);
}
while ((repeat == 'y') || (repeat == 'Y'));
}
}
Explanation / Answer
note: I wote Pateient.java class to make your PatientDemo.java work.If you need any modifications I will do it.Just Tell me if any Thank You.
_______________
Patient.java
public class Patient {
private String name;
private String SSN;
public Patient() {
}
public Patient(String name) {
this.name = name;
this.SSN="122-22-2222";
}
public Patient(String name, String sSN) {
this.name = name;
this.SSN = sSN;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSSN() {
return SSN;
}
public void setSSN(String sSN) {
SSN = sSN;
}
@Override
public String toString() {
return "Patient Name=" + name + ", SSN=" + SSN ;
}
public boolean equals(Patient p) {
if (SSN == null) {
if (p.SSN != null)
return false;
} else if (!SSN.equals(p.SSN))
return false;
if (name == null) {
if (p.name != null)
return false;
} else if (!name.equals(p.name))
return false;
return true;
}
}
____________________
PatientDemo.java
import java.util.Scanner;
public class PatientDemo
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
char repeat;
do
{
//Test the constructors (uses writeOutput method)
Patient p1 = new Patient();
System.out.println("=========================");
System.out.println("Test constructor with just name:");
Patient p2 = new Patient("English");
System.out.println("=========================");
System.out.println("test constructor with both name and SSn:");
Patient p3 = new Patient("Yosarian", "777-77-7777");
System.out.println("=========================");
//Test methods to change, return and write values
//change all
System.out.println("Test to change name & SSN:");
System.out.println();
System.out.println("Before:");
System.out.println("Name:"+p3.getName());
System.out.println("SSN:"+p3.getSSN());
System.out.println("After");
p3.setName("Willaims");
p3.setSSN("122-22-6666");
System.out.println(p3.toString());
System.out.println("=========================");
System.out.println("Test to change name:");
p1.setName("Johnson");
System.out.println("=========================");
System.out.println("Test to change SSN:");
p1.setSSN("145-56-7899");
System.out.println("=========================");
System.out.println("Test to return name:");
System.out.println("Name:"+p1.getName());
System.out.println();
System.out.println();
System.out.println("First equals test:");
if(p1.equals(p2))
System.out.println("Patient1 is equal to Patient2");
else
System.out.println("Patient1 is not equal to Patient2");
//Create 2nd Patient with same insurance values
Patient p4 = new Patient("Faith", "222-22-2222");
System.out.println();
System.out.println("First patient's values:");
System.out.println(p3.toString());
System.out.println("Second patient's values:");
System.out.println(p4.toString());
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'));
}
}
______________________
Output:
=========================
Test constructor with just name:
=========================
test constructor with both name and SSn:
=========================
Test to change name & SSN:
Before:
Name:Yosarian
SSN:777-77-7777
After
Patient Name=Willaims, SSN=122-22-6666
=========================
Test to change name:
=========================
Test to change SSN:
=========================
Test to return name:
Name:Johnson
First equals test:
Patient1 is not equal to Patient2
First patient's values:
Patient Name=Willaims, SSN=122-22-6666
Second patient's values:
Patient Name=Faith, SSN=222-22-2222
=========================
Do again? (Y for Yes, or N for No)
n
_______________Thank You
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.