In: Computer Science
Problem 2:
(20 pts) Create a Patient class which has private fields for patientid, lastname,
firstname, age, and email. Create public data items for each of these private fields with get and
set methods. The entire lastname must be stored in uppercase. Create a main class which
instantiates a patient object and sets values for each data item within the class. Display the
data in the object to the console window
Patient class
Main class
Console Window
You can copy code from below.
package com.company;
public class patient {
private String patientid;
private String lastname;
private String firstname;
private int age;
private String email;
//getters
public String getPatientid() {
return patientid;
}
public String getLastname() {
return lastname;
}
public String getFirstname() {
return firstname;
}
public int getAge() {
return age;
}
public String getEmail() {
return email;
}
// setters
public void setPatientid(String patientid) {
this.patientid = patientid;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public void setAge(int age) {
this.age = age;
}
public void setEmail(String email) {
this.email = email.toUpperCase(); //stored in uppercase
}
public void display() {
System.out.println("Patient ID: " + patientid);
System.out.println("Name: " + firstname + " " + lastname);
System.out.println("Age: " + age);
System.out.println("Email: " + email);
}
}
package com.company;
public class Main {
public static void main(String[] args) {
//patient object instantiation
patient Patient1 = new patient();
//setting values of data item
Patient1.setPatientid("001");
Patient1.setFirstname("Arun");
Patient1.setLastname("Singh");
Patient1.setAge(32);
Patient1.setEmail("[email protected]");
//display all the items, this method is mentioned in the patient class
Patient1.display();
}
}
As no particular language was mentioned, i did it in JAVA.
I also hope it answers your question. Thank you
If you still got any doubt, do post it in comment