In: Computer Science
Write a C# console program that continually asks the user "Do you want
to enter a name (Y/N)? ". Use a "while" loop to accomplish this. As long as the user enters
either an upper or lowercase 'Y', then prompt to the screen "Enter First and Last Name: " and
then get keyboard input of the name. After entering the name, display the name to the screen.
---
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.
---
Modify the Patient class with two overloaded constructors: A new default
constructor which initializes the data items for a patient object using code within the
constructor (use any data). A second constructor with parameters to pass all the data items
into the object at the time of instantiation. Create a test main class which instantiates two
objects. Instantiate the first object using the default constructor and the second object using
the constructor with the parameters.
---
Modify the main class in the patient application to include a display
method that has a parameter to pass a patient object and display its content.
---
Modify the patient class with two overloaded methods to display a bill for a
standard visit based on age. In the first method do not use any parameters to pass in data. If
the patient is over 65, then a standard visit is $75. If the patient is under 65, then the standard
doctors office visit is $125. Build a second method where you pass in a discount rate. If the
patient is over 65, then apply the discount rate to a standard rate of $125. Create a main
method that calls both of these methods and displays the results.
-----
Create two subclasses called outpatient and inpatient which inherit from
the patient base class. The outpatient class has an additional data field called doctorOfficeID
and the inpatient class has an additional data item called hospitalID. Write a main method that
creates inpatient and outpatient objects. Sets data for these objects and display the data.
---
Modify the base class of Problem 5 to be an abstract class with an abstract
display method called displayPatient that does not implement any code. Create specific
implementations for this method in both the outpatient and inpatient subclasses
Question 1:
Application name :ConsoleApp_NameDisplay
Type of application :Console application
Language used :C#
Program.cs :
//namespace
using System;
//application namespace
namespace ConsoleApp_NameDisplay
{
class Program //C# class
{
//main() method
static void Main(string[] args)
{
Console.WriteLine("Do you want to enter a name(Y / N) ? ");
//reading user response
string userResponse = Console.ReadLine();
//using while loop
while(true)
{
//This line will ask user First name and last name
Console.Write("Enter First and Last Name:");
//reading first and last name
string firstLastName = Console.ReadLine();
//display first name and last name
Console.WriteLine(firstLastName);
//asking user whether want to continue
Console.WriteLine("Do you want to enter a name(Y / N) ? ");
//reading user response
userResponse = Console.ReadLine();
//checking firstLastName
if (userResponse.ToUpper()== "Y")
{
//when user response is Y then continue while loop
continue;
}
else
{
break;//break while loop
}
}
}
}
}
=========================================================
Output :
****************************************************
Question 2 :
Application name :ConsoleApp_Patient
Type of application :Console application
Language used :C#
Patient.cs :
//namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//application namespace
namespace ConsoleApp_Patient
{
class Patient //C# class
{
//private fields for patientid, lastname,firstname, age, and
email.
private int patientid;
private string lastname;
private string firstname;
private int age;
private string email;
//public data items for each of these private fields with get
and
//set methods
public int PatientID //Public field for patientid
{
get { return patientid; }
set
{
patientid = value;//set patinetid
}
}
public string LastName //Public field for lastname
{
get { return lastname; }
set
{
lastname = value.ToUpper();//set lastname in upper case
}
}
public string FirstName //Public field for firstname
{
get { return firstname; }
set
{
firstname = value;//set firstname
}
}
public int Age //Public field for age
{
get { return age; }
set
{
age = value;//set age
}
}
public string Email //Public field for email
{
get { return email; }
set
{
email = value;//set email
}
}
}
}
********************************
Program.cs :
//namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//application namespace
namespace ConsoleApp_Patient
{
class Program //C# class
{
//Main() method
static void Main(string[] args)
{
//Object of patient class
Patient patient = new Patient();
//asking user patientid
Console.Write("Enter patientid : ");
//reading patientid
patient.PatientID = int.Parse(Console.ReadLine());
//asking user lastname
Console.Write("Enter lastname : ");
//reading lastname
patient.LastName = Console.ReadLine();
//asking user firstname
Console.Write("Enter firstname : ");
//reading firstname
patient.FirstName = Console.ReadLine();
//asking user age
Console.Write("Enter age : ");
//reading age
patient.Age = int.Parse(Console.ReadLine());
//asking user email
Console.Write("Enter email : ");
//reading email
patient.Email = Console.ReadLine();
//display patient details
Console.WriteLine(patient.PatientID+" , "+patient.LastName+" ,
"+patient.FirstName+" , "+patient.Age+" , "+patient.Email);
//to hold the screen
Console.ReadKey();
}
}
}
===========================================
Output :
*************************************************
Question 3 :modifications
Patient.cs :
//namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//application namespace
namespace ConsoleApp_Patient
{
class Patient //C# class
{
//private fields for patientid, lastname,firstname, age, and
email.
private int patientid;
private string lastname;
private string firstname;
private int age;
private string email;
//default constructor
public Patient()
{
patientid = 102;
lastname = "defaultLastName";
firstname = "defaultFirstName";
age = 21;
email = "[email protected]";
}
//overloaded constructor
public Patient(int pid,string lname,string fname,int ag,string
mail)
{
patientid = pid;
lastname = lname;
firstname = fname;
age = ag;
email = mail;
}
//public data items for each of these private fields with get
and
//set methods
public int PatientID //Public field for patientid
{
get { return patientid; }
set
{
patientid = value;//set patinetid
}
}
public string LastName //Public field for lastname
{
get { return lastname; }
set
{
lastname = value.ToUpper();//set lastname in upper case
}
}
public string FirstName //Public field for firstname
{
get { return firstname; }
set
{
firstname = value;//set firstname
}
}
public int Age //Public field for age
{
get { return age; }
set
{
age = value;//set age
}
}
public string Email //Public field for email
{
get { return email; }
set
{
email = value;//set email
}
}
}
}
********************************************
Program.cs :
//namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//application namespace
namespace ConsoleApp_Patient
{
class Program //C# class
{
//Main() method
static void Main(string[] args)
{
//Object of patient class
Patient patient = new Patient();
//asking user patientid
Console.Write("Enter patientid : ");
//reading patientid
int patientID = int.Parse(Console.ReadLine());
//asking user lastname
Console.Write("Enter lastname : ");
//reading lastname
string lastname = Console.ReadLine();
//asking user firstname
Console.Write("Enter firstname : ");
//reading firstname
string firstname = Console.ReadLine();
//asking user age
Console.Write("Enter age : ");
//reading age
int age = int.Parse(Console.ReadLine());
//asking user email
Console.Write("Enter email : ");
//reading email
string email = Console.ReadLine();
//display patient details
Console.WriteLine(patient.PatientID+" , "+patient.LastName+" ,
"+patient.FirstName+" , "+patient.Age+" , "+patient.Email);
//creating another object of
Patient patient1 = new Patient(patientID, lastname, firstname, age,
email);
//display patient details
Console.WriteLine(patient1.PatientID + " , " + patient1.LastName +
" , " + patient1.FirstName + " , " + patient1.Age + " , " +
patient1.Email);
//to hold the screen
Console.ReadKey();
}
}
}
=========================================
Output :
*******************************************
Question 4 :
Patient.cs :
//namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//application namespace
namespace ConsoleApp_Patient
{
class Patient //C# class
{
//private fields for patientid, lastname,firstname, age, and
email.
private int patientid;
private string lastname;
private string firstname;
private int age;
private string email;
//default constructor
public Patient()
{
patientid = 102;
lastname = "defaultLastName";
firstname = "defaultFirstName";
age = 21;
email = "[email protected]";
}
//overloaded constructor
public Patient(int pid,string lname,string fname,int ag,string
mail)
{
patientid = pid;
lastname = lname;
firstname = fname;
age = ag;
email = mail;
}
//public data items for each of these private fields with get
and
//set methods
public int PatientID //Public field for patientid
{
get { return patientid; }
set
{
patientid = value;//set patinetid
}
}
public string LastName //Public field for lastname
{
get { return lastname; }
set
{
lastname = value.ToUpper();//set lastname in upper case
}
}
public string FirstName //Public field for firstname
{
get { return firstname; }
set
{
firstname = value;//set firstname
}
}
public int Age //Public field for age
{
get { return age; }
set
{
age = value;//set age
}
}
public string Email //Public field for email
{
get { return email; }
set
{
email = value;//set email
}
}
//method to calculate bill
public double calculateBill()
{
double fee = 0;//declaring variable to store fee
//checking age
if(age>65)
{
//when age is greater than 65 then
fee = 75;
}
else
{
//If the patient is under 65, then the standard
// doctors office visit is $125.
fee = 125;
}
return fee;
}
//method to calculate bill
public double calculateBill(double discountRate)
{
double fee = 0;//declaring variable to store fee
//checking age
if (age > 65)
{
//when age is greater than 65 then
fee = 75-75* discountRate;
}
else
{
//If the patient is under 65, then the standard
// doctors office visit is $125.
fee = 125-125*discountRate;
}
return fee;
}
}
}
*******************************************
Program.cs :
//namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//application namespace
namespace ConsoleApp_Patient
{
class Program //C# class
{
//Main() method
static void Main(string[] args)
{
//asking user patientid
Console.Write("Enter patientid : ");
//reading patientid
int patientID = int.Parse(Console.ReadLine());
//asking user lastname
Console.Write("Enter lastname : ");
//reading lastname
string lastname = Console.ReadLine();
//asking user firstname
Console.Write("Enter firstname : ");
//reading firstname
string firstname = Console.ReadLine();
//asking user age
Console.Write("Enter age : ");
//reading age
int age = int.Parse(Console.ReadLine());
//asking user email
Console.Write("Enter email : ");
//reading email
string email = Console.ReadLine();
//creating another object of
Patient patient1 = new Patient(patientID, lastname, firstname, age,
email);
//display patient details
Console.WriteLine(patient1.PatientID + " , " + patient1.LastName +
" , " + patient1.FirstName + " , " + patient1.Age + " , " +
patient1.Email);
//calling method and passing age
Console.WriteLine("Bill : "+patient1.calculateBill());
//asking user discount rate
Console.Write("Discount rate : ");
//double discount rate
double discountRate = double.Parse(Console.ReadLine());
//calling method and passing age
Console.WriteLine("Bill : " +
patient1.calculateBill(discountRate/100));
//to hold the screen
Console.ReadKey();
}
}
}
==========================================
Output :