[go: up one dir, main page]

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

RunBloodData Java

The document defines a BloodData class with static variables for blood type and RH factor. It contains two constructors, one default and one that accepts blood type and RH factor as parameters. The main method prompts the user for input, creates a BloodData object using the appropriate constructor, and calls the display method to output the blood type and RH factor.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views2 pages

RunBloodData Java

The document defines a BloodData class with static variables for blood type and RH factor. It contains two constructors, one default and one that accepts blood type and RH factor as parameters. The main method prompts the user for input, creates a BloodData object using the appropriate constructor, and calls the display method to output the blood type and RH factor.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Jhance Giyan Regoniel

BSIT21B

import java.util.*;

class BloodData {

static String bloodType;

static String rhFactor;

public BloodData() {

bloodType = "O";

rhFactor = "+";

public BloodData(String bt, String rh) { // create an overloaded constructor

bloodType = bt;

rhFactor = rh;

public void display() {

System.out.println("Blood Type: " + bloodType);

System.out.println("Rhesus Factor: " + rhFactor);

public class RunBloodData {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);


System.out.print("Enter blood type (O, A, B, AB): ");// named blood type for accepting

String input1 = scanner.nextLine();

System.out.print("Enter Rhesus factor (+ or -): ");// instantiate a blooddata

String input2 = scanner.nextLine();

BloodData bd;

if (input1.isEmpty() || input2.isEmpty()) {

bd = new BloodData();

} else {

bd = new BloodData(input1, input2);

bd.display();// print the confirmation message

You might also like