Docsity

Object_oriented_programming tutorial questions, Cheat Sheet of Object Oriented Programming

Toggle sidebar
bg1
OBJECT ORIENTED PROGRAMMING
TUTORIAL QUESTIONS – BIOMEDICAL ENGINEERING EDITION
BENG24BE – Adapted from Tutorial Questions-1 (Java, Classes & Objects)
QUESTION ONE – Patient Vital Signs Monitoring System
A hospital ward requires a simple computerized system to assist nurses in monitoring
patient vital signs. The system should store basic patient information such as patient ID,
patient name, ward, and three systolic blood pressure readings taken during a shift. The
nurse should be able to create patient vital-sign records, calculate the average blood
pressure reading, determine whether the patient's condition is normal or requires
attention, and display the complete vital signs record.
Required
ā—Develop a Java program that creates a class named VitalSigns with appropriate
attributes and methods to perform the following operations:
ā—1. Store patient vital sign details.
ā—2. Calculate the average blood pressure reading using a method.
ā—3. Determine the patient's condition status using a method.
ā—4. Display patient vital sign information using a display method.
ā—Create at least three patient objects in the main() method and demonstrate the
implemented methods.
Java Solution
class VitalSigns {
String patientID;
String patientName;
String ward;
double reading1;
double reading2;
double reading3;
VitalSigns(String id, String name, String ward,
double r1, double r2, double r3){
patientID = id;
patientName = name;
this.ward = ward;
reading1 = r1;
reading2 = r2;
reading3 = r3;
}
double calculateAverageBP(){
return (reading1 + reading2 + reading3) / 3;
}
String checkCondition(){
if(calculateAverageBP() >= 90 && calculateAverageBP() <= 120)
return "NORMAL";
else
return "REQUIRES ATTENTION";
}
void displayVitalSigns(){
System.out.println("Patient ID: " + patientID);
System.out.println("Name: " + patientName);
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Object_oriented_programming tutorial questions and more Cheat Sheet Object Oriented Programming in PDF only on Docsity!

OBJECT ORIENTED PROGRAMMING

TUTORIAL QUESTIONS – BIOMEDICAL ENGINEERING EDITION

BENG24BE – Adapted from Tutorial Questions-1 (Java, Classes & Objects)

QUESTION ONE – Patient Vital Signs Monitoring System

A hospital ward requires a simple computerized system to assist nurses in monitoring

patient vital signs. The system should store basic patient information such as patient ID,

patient name, ward, and three systolic blood pressure readings taken during a shift. The

nurse should be able to create patient vital-sign records, calculate the average blood

pressure reading, determine whether the patient's condition is normal or requires

attention, and display the complete vital signs record.

Required

ā— Develop a Java program that creates a class named VitalSigns with appropriate

attributes and methods to perform the following operations:

ā— 1. Store patient vital sign details.

ā— 2. Calculate the average blood pressure reading using a method.

ā— 3. Determine the patient's condition status using a method.

ā— 4. Display patient vital sign information using a display method.

ā— Create at least three patient objects in the main() method and demonstrate the

implemented methods.

Java Solution

class VitalSigns { String patientID; String patientName; String ward; double reading1; double reading2; double reading3; VitalSigns(String id, String name, String ward, double r1, double r2, double r3){ patientID = id; patientName = name; this.ward = ward; reading1 = r1; reading2 = r2; reading3 = r3; } double calculateAverageBP(){ return (reading1 + reading2 + reading3) / 3; } String checkCondition(){ if(calculateAverageBP() >= 90 && calculateAverageBP() <= 120) return "NORMAL"; else return "REQUIRES ATTENTION"; } void displayVitalSigns(){ System.out.println("Patient ID: " + patientID); System.out.println("Name: " + patientName);

System.out.println("Ward: " + ward); System.out.println("Average Systolic BP: " + calculateAverageBP()); System.out.println("Condition: " + checkCondition()); } } public class Main { public static void main(String args[]){ VitalSigns p1 = new VitalSigns("PT001","John Peter","Ward A",118,122,120); VitalSigns p2 = new VitalSigns("PT002","Mary James","Ward B",135,140,138); p1.displayVitalSigns(); System.out.println("----------------"); p2.displayVitalSigns(); } }

QUESTION TWO – Medical Oxygen Cylinder Stock Management System

A hospital biomedical stores department wants to develop a simple application to manage

oxygen cylinder stock levels. The application should allow the storekeeper to create a

cylinder record, refill a cylinder, consume (withdraw) oxygen from a cylinder during use,

and display the current oxygen level. The system should demonstrate the use of classes,

objects, and methods for performing stock operations.

Required

ā— Develop a Java program containing a class named OxygenCylinder with the

following methods:

ā— • refill()

ā— • consume()

ā— • calculateLevel()

ā— • displayCylinderDetails()

ā— Create objects representing different cylinders and demonstrate performing

different transactions using the created objects.

Java Solution

class OxygenCylinder { String cylinderID; String location; double levelLitres; OxygenCylinder(String id, String location, double level){ cylinderID = id; this.location = location; levelLitres = level; } void refill(double amount){ levelLitres += amount; System.out.println("Refill successful"); } void consume(double amount){ if(amount <= levelLitres){ levelLitres -= amount;

this.consultation = consultation; this.treatment = treatment; } double calculateBill(){ return consultation + treatment; } void displayPatient(){ System.out.println("Patient Number: " + patientNumber); System.out.println("Name: " + name); System.out.println("Age: " + age); System.out.println("Total Bill: " + calculateBill()); } } public class Main{ public static void main(String args[]){ PatientBilling p1 = new PatientBilling(101,"John",35,50000,150000); PatientBilling p2 = new PatientBilling(102,"Mary",28,50000,100000); p1.displayPatient(); System.out.println("----------------"); p2.displayPatient(); } }

QUESTION FOUR – Biomedical Equipment Inventory System

A hospital biomedical engineering workshop requires a simple inventory application to

record available medical devices. Each device record should contain device identification

number, device type, power rating, calibration interval (in months), and purchase price.

The biomedical engineer should be able to calculate the total value of devices and display

individual device specifications.

Required

ā— Develop a Java program using a class named BiomedicalDevice. The class should

contain methods to:

ā— • Store device information.

ā— • Calculate device value.

ā— • Display device specifications.

ā— Create at least five device objects and use methods to process and display their

information.

Java Solution

class BiomedicalDevice { String deviceID; String deviceType; int powerRatingWatts; int calibrationIntervalMonths; double price; BiomedicalDevice(String id, String type, int power, int interval, double price){ deviceID = id;

deviceType = type; powerRatingWatts = power; calibrationIntervalMonths = interval; this.price = price; } double calculateValue(){ return price; } void displayDevice(){ System.out.println("Device ID: " + deviceID); System.out.println("Type: " + deviceType); System.out.println("Power Rating: " + powerRatingWatts + "W"); System.out.println("Calibration Interval: " + calibrationIntervalMonths + " months"); System.out.println("Price: " + calculateValue()); } } public class Main{ public static void main(String args[]){ BiomedicalDevice d1 = new BiomedicalDevice("BD001","Patient Monitor",60,6,3500000); BiomedicalDevice d2 = new BiomedicalDevice("BD002","Infusion Pump",40,12,1800000); BiomedicalDevice d3 = new BiomedicalDevice("BD003","ECG Machine",50,6,5000000); BiomedicalDevice d4 = new BiomedicalDevice("BD004","Pulse Oximeter",5,12,250000); BiomedicalDevice d5 = new BiomedicalDevice("BD005","Defibrillator",100,6,9000000); d1.displayDevice(); System.out.println("----------------"); d2.displayDevice(); System.out.println("----------------"); d3.displayDevice(); System.out.println("----------------"); d4.displayDevice(); System.out.println("----------------"); d5.displayDevice(); } }

QUESTION FIVE – Biomedical Technician Payroll System

A hospital engineering department wants to automate basic payroll calculations for

biomedical technicians. The system should maintain technician information such as

technician number, technician name, working hours, and hourly payment rate. The

application should calculate the monthly salary and display payment details.

Required

ā— Develop a Java program with a class named Technician containing methods to:

ā— • Accept technician details.

ā— • Calculate salary based on working hours and hourly rate.

ā— • Display technician salary information.

int journalID; String title; String publisher; double price; MedicalJournal(int id, String title, String publisher, double price){ journalID = id; this.title = title; this.publisher = publisher; this.price = price; } double calculatePrice(){ return price; } void displayJournal(){ System.out.println("Journal ID: " + journalID); System.out.println("Title: " + title); System.out.println("Publisher: " + publisher); System.out.println("Price: " + calculatePrice()); } } public class Main { public static void main(String args[]){ MedicalJournal j1 = new MedicalJournal(1,"Biomedical Instrumentation","IEEE Press",85000); MedicalJournal j2 = new MedicalJournal(2,"Principles of Medical Imaging","Elsevier",95000); j1.displayJournal(); System.out.println("----------------"); j2.displayJournal(); } }

QUESTION SEVEN – Medical Equipment Maintenance Service System

A hospital biomedical engineering workshop needs a simple application to record medical

devices brought in for maintenance. The system should store device serial number, device

model, service type, and service cost. The application should calculate total service

charges and generate service reports.

Required

ā— Develop a Java program using a class named EquipmentService. Implement

methods to:

ā— • Record device information.

ā— • Calculate service charges.

ā— • Display service reports.

ā— Create different objects representing serviced devices and demonstrate method

execution.

Java Solution

class EquipmentService {

String serialNumber; String model; String serviceType; double serviceCost; EquipmentService(String serial, String model, String type, double cost){ serialNumber = serial; this.model = model; serviceType = type; serviceCost = cost; } double calculateServiceCharge(){ return serviceCost; } void displayServiceReport(){ System.out.println("Serial Number: " + serialNumber); System.out.println("Model: " + model); System.out.println("Service Type: " + serviceType); System.out.println("Service Cost: " + calculateServiceCharge()); } } public class Main { public static void main(String args[]){ EquipmentService s1 = new EquipmentService("SN123ABC","Philips Patient Monitor","Preventive Maintenance",250000); EquipmentService s2 = new EquipmentService("SN456DEF","Drager Ventilator","Calibration",180000); s1.displayServiceReport(); System.out.println("----------------"); s2.displayServiceReport(); } }

QUESTION EIGHT – Hospital Oxygen Consumption Billing System

A hospital biomedical stores department requires a simple application to calculate monthly

oxygen consumption charges for different wards. Each ward record should contain ward

number, ward name, previous cylinder meter reading, current cylinder meter reading, and

cost per unit consumed. The system should calculate oxygen consumption and generate

the ward's bill.

Required

ā— Develop a Java program with a class named OxygenBilling containing methods to:

ā— • Calculate consumed units.

ā— • Calculate total bill amount.

ā— • Display ward billing information.

ā— Create multiple ward objects and test all methods.

Java Solution

class OxygenBilling { int wardNumber; String wardName;

class TemperatureMonitor { String patientName; double morningTemperature; double afternoonTemperature; double eveningTemperature; TemperatureMonitor(String patientName, double morning, double afternoon, double evening){ this.patientName = patientName; morningTemperature = morning; afternoonTemperature = afternoon; eveningTemperature = evening; } double calculateAverage(){ return (morningTemperature + afternoonTemperature + eveningTemperature) / 3; } String checkCondition(){ if(calculateAverage() > 37.5) return "Feverish"; else return "Normal Temperature"; } void displayTemperature(){ System.out.println("Patient: " + patientName); System.out.println("Average Temperature: " + calculateAverage() + " °C"); System.out.println("Condition: " + checkCondition()); } } public class Main { public static void main(String args[]){ TemperatureMonitor t1 = new TemperatureMonitor("John Peter",36.8,38.2,37.9); TemperatureMonitor t2 = new TemperatureMonitor("Mary James",36.2,36.5,36.4); t1.displayTemperature(); System.out.println("----------------"); t2.displayTemperature(); } }

QUESTION TEN – Pharmacy Medical Supplies Inventory System

A hospital pharmacy requires a simple application for managing medical supplies

information. Each supply item should contain item code, item name, quantity available,

and unit price. The system should calculate total supply value and display supply

information.

Required

ā— Develop a Java program using a class named MedicalSupply with methods to:

ā— • Register supply item details.

ā— • Calculate total supply value.

ā— • Display supply information.

ā— Create different supply objects and demonstrate the use of methods.

Java Solution

class MedicalSupply { String itemCode; String itemName; int quantity; double unitPrice; MedicalSupply(String code, String name, int quantity, double price){ itemCode = code; itemName = name; this.quantity = quantity; unitPrice = price; } double calculateTotalValue(){ return quantity * unitPrice; } void displaySupply(){ System.out.println("Item Code: " + itemCode); System.out.println("Item Name: " + itemName); System.out.println("Quantity: " + quantity); System.out.println("Total Value: " + calculateTotalValue()); } } public class Main { public static void main(String args[]){ MedicalSupply s1 = new MedicalSupply("S001","Surgical Gloves (box)",50,15000); MedicalSupply s2 = new MedicalSupply("S002","IV Cannula",200,2000); s1.displaySupply(); System.out.println("----------------"); s2.displaySupply(); } }

QUESTION ELEVEN – Infusion Pump Fluid Flow Rate Calculator

A hospital ICU wants to monitor the performance of its infusion pumps. The system should

record pump ID, volume of fluid infused (in millilitres), and time taken (in hours). It should

calculate the fluid flow rate and display pump performance information.

Required

ā— Develop a Java program using a class named InfusionPump containing methods to:

ā— • Record pump data.

ā— • Calculate flow rate.

ā— • Display results.

ā— Create objects for different pumps and execute the methods.

Java Solution

class InfusionPump { String pumpID;

double add(){ return dose1 + dose2; } double subtract(){ return dose1 - dose2; } double multiply(){ return dose1 * dose2; } double divide(){ return dose1 / dose2; } void displayResults(){ System.out.println("Addition: " + add()); System.out.println("Subtraction: " + subtract()); System.out.println("Multiplication: " + multiply()); System.out.println("Division: " + divide()); } } public class Main { public static void main(String args[]){ DosageCalculator c1 = new DosageCalculator(20,5); c1.displayResults(); } }

QUESTION THIRTEEN – Physiotherapy Session Attendance System

A hospital physiotherapy department requires a simple system to monitor patient

attendance for rehabilitation sessions. The system should store patient details, number of

attended sessions, and total number of scheduled sessions. It should calculate attendance

percentage and display attendance status.

Required

ā— Develop a Java program using a class named TherapyAttendance with methods to:

ā— • Record attendance details.

ā— • Calculate attendance percentage.

ā— • Display attendance report.

ā— Create several objects and demonstrate method execution.

Java Solution

class TherapyAttendance { String patientName; String patientID; int attendedSessions; int totalSessions; TherapyAttendance(String name, String id, int attended, int total){ patientName = name;

patientID = id; attendedSessions = attended; totalSessions = total; } double calculateAttendancePercentage(){ return ((double) attendedSessions / totalSessions) * 100; } String checkAttendanceStatus(){ if(calculateAttendancePercentage() >= 75) return "Good Attendance"; else return "Poor Attendance"; } void displayAttendance(){ System.out.println("Patient Name: " + patientName); System.out.println("Patient ID: " + patientID); System.out.println("Attendance Percentage: " + calculateAttendancePercentage() + "%"); System.out.println("Status: " + checkAttendanceStatus()); } } public class Main { public static void main(String args[]){ TherapyAttendance a1 = new TherapyAttendance("John Peter","PT001",35,40); TherapyAttendance a2 = new TherapyAttendance("Mary James","PT002",25,40); a1.displayAttendance(); System.out.println("----------------"); a2.displayAttendance(); } }

QUESTION FOURTEEN – Medical Equipment Ownership Cost System

A hospital engineering department wants to maintain records of medical equipment

ownership costs. Each equipment record should contain equipment name, serial number,

purchase cost, and maintenance cost. The system should calculate total ownership cost

and display equipment information.

Required

ā— Develop a Java program using a class named MedicalEquipmentCost with methods

to:

ā— • Store equipment details.

ā— • Calculate total cost.

ā— • Display equipment report.

ā— Create multiple equipment objects and test the program.

Java Solution

class MedicalEquipmentCost { String equipmentName; String serialNumber; double purchaseCost;

EquipmentLease(String name, double amount, double rate, int period){ hospitalName = name; leaseAmount = amount; interestRate = rate; repaymentPeriod = period; } double calculateInterest(){ return leaseAmount * (interestRate / 100) * repaymentPeriod; } double calculateTotalRepayment(){ return leaseAmount + calculateInterest(); } void displayLeaseInformation(){ System.out.println("Hospital Name: " + hospitalName); System.out.println("Lease Amount: " + leaseAmount); System.out.println("Interest Amount: " + calculateInterest()); System.out.println("Total Repayment: " + calculateTotalRepayment()); } } public class Main { public static void main(String args[]){ EquipmentLease l1 = new EquipmentLease("Muhimbili Hospital",2000000,10,2); EquipmentLease l2 = new EquipmentLease("Bugando Hospital",3000000,8,3); l1.displayLeaseInformation(); System.out.println("----------------"); l2.displayLeaseInformation(); } }