Question

Java Eclipse Coding question: Use data abstraction (real-world modeling) to come up with 3 instance variables...

Java Eclipse Coding question:

Use data abstraction (real-world modeling) to come up with 3 instance variables and 2 effectors for a new data type – the class HospitalPatient. You have the freedom to design the instance variables and effectors.

instance variables effectors

1. 1.

2. 2.

3.

Write the code for class HospitalPatient, according to the requirement above. Include the default constructors with no argument, and the constructor with all arguments. Provide a getter and setter for each individual instance variable. Provide the two effectors that you design above. All instance data are private and all methods are public. Observe the coding conventions, including proper indent. No user input is needed.

Write the code for an application class that has a main method, and in the main method, creates two instances of class HospitalPatient, one with default constructor and one with the other constructor. Then as use to input necessary variables, and then use the setters to set the input variables into the object that you created with default constructor. Then call the effectors of the HospitalPatient and prints out some information about the patients. You can name the class JohnDoeTest, where JohnDoe should be replaced with your name. Observe coding conventions, including proper indent. You can use Scanner class here to get input parameters from user, in order to initialize the object created by the default constructor (the constructor that has no parameter). Only in this application class, you need to obtain user input.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

public class HospitalPatient {

   //variables

   private String name;

   private int age;

   private String disease;

  

   /**

   * @param name

   * @param age

   * @param disease

   */

   public HospitalPatient(String name, int age, String disease) {

       super();

       this.name = name;

       this.age = age;

       this.disease = disease;

   }

   /**

   * Default Constructor

   */

   public HospitalPatient() {

       super();

      

   }

   /**

   * @return the name

   */

   public String getName() {

       return name;

   }

   /**

   * @param name the name to set

   */

   public void setName(String name) {

       this.name = name;

   }

   /**

   * @return the age

   */

   public int getAge() {

       return age;

   }

   /**

   * @param age the age to set

   */

   public void setAge(int age) {

       this.age = age;

   }

   /**

   * @return the disease

   */

   public String getDisease() {

       return disease;

   }

   /**

   * @param disease the disease to set

   */

   public void setDisease(String disease) {

       this.disease = disease;

   }

  

   //effectors

   //give detail of patient

   public String patientDetail(){

       return "Patient Name: " + name + "\nPatient age: "+ age + "\n Patient Disease: " + disease;

   }

  

   //Change patient Condition:If patient is well then provide null value means no disease

   public void changePatientCondition(){

       this.disease = null;

   }

  

}

import java.util.Scanner;

//Refactor class name with your name

public class ShubhamTest {

  

   public static void main(String[] args) {

       HospitalPatient patient1 = new HospitalPatient();

       HospitalPatient patient2 = new HospitalPatient("John", 33, "Fever");

       Scanner sc = new Scanner(System.in);

       System.out.println("Enter The patient name");

       String name = sc.next();

       patient1.setName(name);

       System.out.println("Enter The patient Age");

       int age = sc.nextInt();

       patient1.setAge(age);

       System.out.println("Enter The patient Disease");

       String disease = sc.next();  

       patient1.setDisease(disease);

       System.out.println(patient1.patientDetail());

       System.out.println(patient2.patientDetail());

       //when patient is well

       patient1.changePatientCondition();

       patient2.changePatientCondition();

       System.out.println(patient1.patientDetail());

       System.out.println(patient2.patientDetail());

      

      

   }

}

Sample Output:

Enter The patient name

test

Enter The patient Age

12

Enter The patient Disease

cough

Patient Name: test

Patient age: 12

Patient Disease: cough

Patient Name: John

Patient age: 33

Patient Disease: Fever

Patient Name: test

Patient age: 12

Patient Disease: null

Patient Name: John

Patient age: 33

Patient Disease: null

Add a comment
Know the answer?
Add Answer to:
Java Eclipse Coding question: Use data abstraction (real-world modeling) to come up with 3 instance variables...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters...

    Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters long encryptedPassword : String key int Must be between 1 and 10(inclusive) accountId - A unique integer that identifies each account nextIDNum – a static int that starts at 1000 and is used to generate the accountID no other instance variables needed. Default constructor – set all instance variables to a default value. Parameterized constructor Takes in clearPassword, key. Calls encrypt method to create...

  • In this assignment, you will implement Address and Residence classes. Create a new java project. Part...

    In this assignment, you will implement Address and Residence classes. Create a new java project. Part A Implementation details of Address class: Add and implement a class named Address according to specifications in the UML class diagram. Data fields: street, city, province and zipCode. Constructors: A no-arg constructor that creates a default Address. A constructor that creates an address with the specified street, city, state, and zipCode Getters and setters for all the class fields. toString() to print out all...

  • Programming assignment for Java: Do not add any other instance variables to any class, but you...

    Programming assignment for Java: Do not add any other instance variables to any class, but you can create local variables in a method to accomplish tasks. Do not create any methods other than the ones listed below. Step 1 Develop the following class: Class Name: College Degree Access Modifier: public Instance variables Name: major Access modifier: private Data type: String Name: numberOfCourses Access modifier: private Data type: int Name: courseNameArray Access modifier: private Data type: String Name: courseCreditArray Access modifier:...

  • JAVA :The following are descriptions of classes that you will create. Think of these as service...

    JAVA :The following are descriptions of classes that you will create. Think of these as service providers. They provide a service to who ever want to use them. You will also write a TestClass with a main() method that fully exercises the classes that you create. To exercise a class, make some instances of the class, and call the methods of the class using these objects. Paste in the output from the test program that demonstrates your classes’ functionality. Testing...

  • Create a UML diagram to help design the class described in exercise 3 below. Do this...

    Create a UML diagram to help design the class described in exercise 3 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Baby class object; should they be private or public? Determine what class methods are required; should they be private or public? Write Java code for a Baby class. A Baby has a name of type String and an age of type integer. Supply two constructors:...

  • Need help creating a Java program with mandatory requirements! VERY IMPORTANT: The George account class instance...

    Need help creating a Java program with mandatory requirements! VERY IMPORTANT: The George account class instance must be in the main class, and the requirement of printing a list of transactions for only the ids used when the program runs(Detailed in the Additional simulation requirements) is extremely important! Thank you so very much! Instructions: This homework models after a banking situation with ATM machine. You are required to create three classes, Account, Transaction, and the main class (with the main...

  • This exercise guides you through the process of converting an Area and Perimeter application from a...

    This exercise guides you through the process of converting an Area and Perimeter application from a procedural application to an object-oriented application. Create and use an object 1. Open the project named ch04_ex2_Area and Perimeter that’s stored in the ex_starts folder. Then, review the code for the Main class. 2. Create a class named Rectangle and store it in the murach.rectangle package. 3. In the Rectangle class, add instance variables for length and width. The, code the get and set...

  • C# programming 50 pts Question 2:2 1- Create the base class Book that has the following instance variables, constructor, and methods title (String) isbn (String) authors (String) publisher (Strin...

    C# programming 50 pts Question 2:2 1- Create the base class Book that has the following instance variables, constructor, and methods title (String) isbn (String) authors (String) publisher (String) edition ( int) published year (int) Constructor that takes all of the above variables as input parameters. set/get methods ToString method// that return sting representation of Book object. 2-Create the sub class New_Book that is derived from the base class Book and has the following instance variables, constructor, and methods: title...

  • IN JAVA Create the “MathTest” class. It will have two class variables: 1) a question and...

    IN JAVA Create the “MathTest” class. It will have two class variables: 1) a question and 2) the answer to that question. Please create an accessor and mutator method for both of those variables, without which we would not be able to see or change the question or the answer. There should be a constructor method. We will also have a “ToString” method, which will print the question followed by its answer. The constructor method has two parameters to allow...

  • Objectives: 1. Classes and Data Abstraction?2. User-defined classes?3. Implementation of a class in separate files Part...

    Objectives: 1. Classes and Data Abstraction?2. User-defined classes?3. Implementation of a class in separate files Part 1: In this assignment, you are asked: Stage1:?Design and implement a class named memberType with the following requirements: An object of memberType holds the following information: • Person’s first name (string)?• Person’s last name (string)?• Member identification number (int) • Number of books purchased (int)?• Amount of money spent (double)?The class memberType has member functions that perform operations on objects of memberType. For the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT