You are on page 1of 6

Name: John Patrick B.

Drueco_                         
Date: October 24, 2022_
Section: BT304 | BSIT_

Syntax
import java.util.*;

public class RunBloodData {


public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
System.out.print("Enter blood type of patient: ");
String bt = scan.nextLine().toUpperCase();
System.out.print("Enter the Rhesus factor (+ or -): ");
String rh = scan.nextLine();

if (bt.equals ("") && rh.equals("")){


BloodData bd = new BloodData();
bd.display();
}
else {
BloodData bd = new BloodData();
bd.setBloodType(bt);
bd.setRhFactor(rh);
bd.display();
}
}
}
class BloodData {
private String bloodType;
private String rhFactor;

public BloodData(){
bloodType = "O";
rhFactor = "+";
}
public void setBloodType(String bloodType){
this.bloodType = bloodType;
}
public String getBloodType(){
return bloodType;
}
public void setRhFactor(String rhFactor){
this.rhFactor = rhFactor;
}
public String getRhFactor(){
return rhFactor;
}
public void display() {

System.out.print(getBloodType() + getRhFactor() + " is added to the blood bank.");

}
}
// John Patrick Drueco | BT304 / BSIT
Outputs: `
Explanation

In line 5 to 9 is consist of scanner, which is where the


user inputs the blood type and rhesus factor to stores in
blood bank.

In line 10 to 22 here we can see the if else statement, in if


condition if the user inputs blank it will display a default blood
type and rhesus factor which it contains the variable bd. In else
condition it also display the variable bd but when user inputs
something like A+, A-, and etc. as the program required to
input by the user it will display that.

To sum up the first class, basically it just shows here the scanner or the
user needed to input and the if else statement which will display by the
user inputs.
In second class, the bloodType and rhFactor is private which is
this access modifier it can only be accessed within its own class.
Therefore, I use the setter and getter methods or the encapsulation
to able to call or access the method and lastly to be able to display
or print the method base on the user inputs, if the if condition this
class will program to print the default blood type and rhesus
factor.

You might also like