The document describes a Java program that takes in a blood type and Rh factor from a user and creates a BloodData object. If no input is provided, it defaults to O+ blood type. It checks the input for valid blood types and Rh factors before creating the BloodData object.
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 ratings0% found this document useful (0 votes)
29 views1 page
Oop Testing
The document describes a Java program that takes in a blood type and Rh factor from a user and creates a BloodData object. If no input is provided, it defaults to O+ blood type. It checks the input for valid blood types and Rh factors before creating the BloodData object.
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/ 1
Constructor
package labexer5; 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 z = sc.nextLine(); System.out.print("Enter the Rhesus factor (+ or -): "); String x = sc.nextLine();
if(z.equals("") && (x.equals(""))){
BloodData bd = new BloodData(); } else if (z.equalsIgnoreCase("O")|| z.equalsIgnoreCase("A")|| z.equalsIgnoreCase("B")|| z.equalsIgnoreCase("AB")&& x.equals("+") ||x.equals("-") ) { BloodData bd2 = new BloodData(z,x); } else {System.out.println("Wrong Input");} } }
public class BloodData {
static String bloodType, rhFactor; public BloodData(){ bloodType = "O"; rhFactor = "+"; System.out.println( bloodType + rhFactor + " is added to the blood bank.");}
public BloodData(String bt, String rh){
bloodType = bt; rhFactor = rh; System.out.println(bloodType + rhFactor + " is added to the blood bank. ");