Ito yung codes before pa i-modify so wala pa yung encapsulation dito:
Java:
class BloodData {
static String bloodType;
static String rhFactor;
public BloodData() {
bloodType = "O";
rhFactor = "+";
}
public BloodData(String bt, String rh) {
bloodType = bt;
rhFactor = rh;
}
public void display() {
System.out.print(bloodType + rhFactor + " is added to the blood bank.");
}
}
Java:
import java.util.Scanner;
public class RunBloodData {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter blood type of patient: ");
String bt = sc.nextLine();
System.out.print("Enter the Rhesus factor (+ or -): ");
String rh = sc.nextLine();
if(bt.equals("") && rh.equals("")) {
BloodData bd = new BloodData();
bd.display();
}
else {
BloodData bd = new BloodData(bt, rh);
bd.display();
}
}
}
Attachments
-
You do not have permission to view the full content of this post. Log in or register now.
Last edited: