[go: up one dir, main page]

0% found this document useful (0 votes)
41 views2 pages

Constructor

The document contains a Java class named BloodData that prompts users to input a patient's blood type and Rhesus factor. It validates the inputs to ensure they are correct before adding the data to a blood bank. The program uses a scanner for user input and includes error handling for invalid entries.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views2 pages

Constructor

The document contains a Java class named BloodData that prompts users to input a patient's blood type and Rhesus factor. It validates the inputs to ensure they are correct before adding the data to a blood bank. The program uses a scanner for user input and includes error handling for invalid entries.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

public class BloodData {

static String BloodType;


static String rhFactor;
RunBloodData() {
BloodType=("o");
rhFactor= ("+");
}

public static void main(String[] args) {


Scanner x = new Scanner(System.in);
boolean flag= true;
boolean flag2=true;
BloodData bd= new BloodData();
String input = "";
String rh = "";
while (flag){
System.out.println("Enter blood type of the patient:");
input = x.nextLine();
if(input.equalsIgnoreCase("O")){
flag=false;
}
else if(input.equalsIgnoreCase("A")){
flag=false;
}
else if(input.equalsIgnoreCase("B")){
flag=false;
}
else if(input.equalsIgnoreCase("AB")){
flag=false;
}
else if (input.isEmpty()){
flag=false;
}

else {
System.out.println("Wrong input");
}
}
while (flag2){
System.out.println("Enter the Rhesus Factor (+ or -):");
rh= x.nextLine();

if(rh.equals("+")){
flag2=false;
}
else if (rh.equals("-")){
flag2=false;
}
else if (rh.isEmpty()){
flag2=false;
}
else {
System.out.println("Wrong Input");
}
}

if(input.isEmpty() && rh.isEmpty()){


System.out.println(bd.BloodType+ bd.rhFactor +"is added to the blood
bank:");

}
else if (!(input.isEmpty() && (!rh.isEmpty()))){

System.out.println(input+rh + " " + "is added to the blood bank:");

}
}

You might also like