Can you add Logical Operators with this Blood Type Matching program? import java.util.*; public class BloodType
Question:
Can you add Logical Operators with this Blood Type Matching program?
import java.util.*;
public class BloodType
{
public static void main(String[] args)
{
try (//A scanner for user input
Scanner sc = new Scanner(System.in)) {
//The recipient's blood type should be entered here
System.out.print("Enter recipient blood type: ");
String recBloodType = sc.nextLine();
//The blood type entered will be checked and the message will be displayed
if(recBloodType.equals("A+"))
{
System.out.println("The blood type of a matched potential donors are:");
System.out.println("A+, A-, O+, O-");
}
else
if(recBloodType.equals("A-"))
{
System.out.println("The blood type of a matched potential donors are:");
System.out.println("A-, O-");
}
else if(recBloodType.equals("B+"))
{
System.out.println("The blood type of a matched potential donors are:");
System.out.println("B+, B-, O+, O-");
}
else if(recBloodType.equals("B-"))
{
System.out.println("The blood type of a matched potential donors are:");
System.out.println("B-, O-");
}
else if(recBloodType.equals("AB+"))
{
System.out.println("The blood type of a matched potential donors are:");
System.out.println("Compatible with all blood types");
}
else if(recBloodType.equals("AB-"))
{
System.out.println("The blood type of a matched potential donors are:");
System.out.println("AB-, A-, B-, O-");
}
else if(recBloodType.equals("O+"))
{
System.out.println("The blood type of a matched potential donors are:");
System.out.println("O+, O-");
}
else if(recBloodType.equals("O-"))
{
System.out.println("The blood type of a matched potential donors are:");
System.out.println("O-");
}
else
{
System.out.println("Invalid recipient blood type!");
}
}
}
}
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates