Question

In: Computer Science

please write this in C # Create a Patient class which has private fields for patientid,...

please write this in C #

Create a Patient class which has private fields for patientid, lastname,

firstname, age, and email. Create public properties 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.

Solutions

Expert Solution

Create a new C# console project with the name PatientInfo. Add the below code in respective files.

Patient.cs

using System;

namespace PatientInfo
{
    class Patient
    {
        //instance variables
        private int patientid;
        private string lastname;
        private string firstname;
        private int age;
        private string email;

        //properties
        //propetry to get and set the patient id
        public int PatientId
        {
            get
            {
                return patientid;
            }
            set
            {
                patientid = value;
            }
        }
        //propetry to get and set the lastname
        public string LastName
        {
            get
            {
                return lastname;
            }
            set
            {
                lastname = value.ToUpper(); //use ToUpper to convert the entire to uppercase
            }
        }
        //propetry to get and set the firstname
        public string FirstName
        {
            get
            {
                return firstname;
            }
            set
            {
                firstname = value;
            }
        }
        //propetry to get and set the age
        public int Age
        {
            get
            {
                return age;
            }
            set
            {
                age = value;
            }
        }
        //propetry to get and set the email
        public string Email
        {
            get
            {
                return email;
            }
            set
            {
                email = value;
            }
        }
    }
}

Program.cs

using System;

namespace PatientInfo
{
    class Program
    {
        static void Main(string[] args)
        {
            //instantiate the patient object
            Patient myPatient = new Patient();
            //set values for each data item
            myPatient.PatientId = 1122;
            myPatient.LastName = "David";
            myPatient.FirstName = "Lee";
            myPatient.Age = 25;
            myPatient.Email = "[email protected]";
            //display the data in the object to the console
            Console.WriteLine("Patient ID: " + myPatient.PatientId);
            Console.WriteLine("Lastname: " + myPatient.LastName);
            Console.WriteLine("Firstname: " + myPatient.FirstName);
            Console.WriteLine("Age: " + myPatient.Age);
            Console.WriteLine("Email: " + myPatient.Email);
            Console.Write("\nPress any to exit..");
            Console.ReadKey();
        }
    }
}

Output:

Code screenshot:

Let me know if you have any concerns with the above solution.


Related Solutions

Problem 2: (20 pts) Create a Patient class which has private fields for patientid, lastname, firstname,...
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
WRITE IN C++ Create a class named Coord in C++ Class has 3 private data items...
WRITE IN C++ Create a class named Coord in C++ Class has 3 private data items               int xCoord;               int yCoord;               int zCoord; write the setters and getters. They should be inline functions               void setXCoord(int)             void setYCoord(int)            void setZCoord(int)               int getXCoord()                     int getYCoord()                   int getZCoord() write a member function named void display() that displays the data items in the following format      blank line      xCoord is                          ????????      yCoord is                          ????????      zCoord...
Create a class named “Car” which has the following fields. The fields correspond to the columns...
Create a class named “Car” which has the following fields. The fields correspond to the columns in the text file except the last one. i. Vehicle_Name : String ii. Engine_Number : String iii. Vehicle_Price : double iv. Profit : double v. Total_Price : double (Total_Price = Vehicle_Price + Vehicle_Price* Profit/100) 2. Write a Java program to read the content of the text file. Each row has the attributes of one Car Object (except Total_Price). 3. After reading the instances of...
INVENTORY CLASS You need to create an Inventory class containing the private data fields, as well...
INVENTORY CLASS You need to create an Inventory class containing the private data fields, as well as the methods for the Inventory class (object). Be sure your Inventory class defines the private data fields, at least one constructor, accessor and mutator methods, method overloading (to handle the data coming into the Inventory class as either a String and/or int/float), as well as all of the methods (methods to calculate) to manipulate the Inventory class (object). The data fields in the...
In C# please and thanks so much, Create an Employee class with five fields: first name,...
In C# please and thanks so much, Create an Employee class with five fields: first name, last name, workID, yearStartedWked, and initSalary. It includes constructor(s) and properties to initialize values for all fields. Create an interface, SalaryCalculate, class that includes two functions: first,CalcYearWorked() function, it takes one parameter (currentyear) and calculates the number of year the worker has been working. The second function, CalcCurSalary() function that calculates the current year salary. Create a Worker classes that is derived from Employee...
Java Q1: Create a class named Triangle, the class must contain: Private data fields base and...
Java Q1: Create a class named Triangle, the class must contain: Private data fields base and height with setter and getter methods. A constructor that sets the values of base and height. A method named toString() that prints the values of base and height. A method named area() that calculates and prints the area of a triangle. Draw the UML diagram for the class. Implement the class. Q2: Write a Java program that creates a two-dimensional array of type integer...
The Account class Create a class named Account, which has the following private properties:
in java The Account class Create a class named Account, which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNumber (), getBalance (), setBalan newBalance). There is no setNumber () once an account is created, its account number cannot change. Now implement these methods: void deposit (double amount) and void withdraw (double amount). For both these methods, if the amount is less than...
The Account class Create a class named Account , which has the following private properties:
 The Account class Create a class named Account , which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNunber(), getBalance(), setBalance (double newBalance) . There is no setNunber() - once an account is created, its account number cannot change. Now implement these methods: void deposit (double anount) and void withdraw(double anount). For both these methods, if the amount is less than zero,...
Create a C# Application. Create a class object called “Employee” which includes the following private variables:...
Create a C# Application. Create a class object called “Employee” which includes the following private variables: firstN lastN idNum wage: holds how much the person makes per hour weekHrsWkd: holds how many total hours the person worked each week regHrsAmt: initialize to a fixed amount of 40 using constructor. regPay otPay After going over the regular hours, the employee gets 1.5x the wage for each additional hour worked. Methods: constructor properties CalcPay(): Calculate the regular pay and overtime pay. Create...
in c#: Create a class named Square that contains fields for area and the length of...
in c#: Create a class named Square that contains fields for area and the length of a side and whose constructor requires a parameter for the length of one side of a Square. The constructor assigns its parameter to the length of the Square’s side field and calls a private method that computes the area field. Also include read-only properties to get a Square’s side and area. Create a class named DemoSquares that instantiates an array of ten Square objects...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT