Learning coding means GreatToCode Be more than a Coder ! Greattocode , Join GreatToCode Community,1000+ Students Trusted On Us .If You want to learn coding, Then GreatToCode Help You.No matter what It Takes !


CODE YOUR WAY TO A MORE FULFILLING And HIGHER PAYING CAREER IN TECH, START CODING FOR FREE Camp With GreatToCode - Join the Thousands learning to code with GreatToCode
Interactive online coding classes for at-home learning with GreatToCode . Try ₹Free Per Month Coding Classes With The Top Teachers . Relationship manager software In Java.

Relationship manager software In Java.

Let's create a simple relationship management software in Java using the console as the user interface. This software will allow you to manage relationships between people by adding, viewing, and searching for relationships. Here's an example implementation to get you started:

```java
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Person {
    private String name;

    public Person(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }
}

class Relationship {
    private Person person1;
    private Person person2;
    private String relationshipType;

    public Relationship(Person person1, Person person2, String relationshipType) {
        this.person1 = person1;
        this.person2 = person2;
        this.relationshipType = relationshipType;
    }

    public Person getPerson1() {
        return person1;
    }

    public Person getPerson2() {
        return person2;
    }

    public String getRelationshipType() {
        return relationshipType;
    }
}

public class RelationshipManager {
    private List<Person> people;
    private List<Relationship> relationships;

    public RelationshipManager() {
        people = new ArrayList<>();
        relationships = new ArrayList<>();
    }

    public void addPerson(String name) {
        Person person = new Person(name);
        people.add(person);
        System.out.println("Person added: " + name);
    }

    public void addRelationship(String person1Name, String person2Name, String relationshipType) {
        Person person1 = findPerson(person1Name);
        Person person2 = findPerson(person2Name);

        if (person1 != null && person2 != null) {
            Relationship relationship = new Relationship(person1, person2, relationshipType);
            relationships.add(relationship);
            System.out.println("Relationship added: " + person1Name + " - " + relationshipType + " - " + person2Name);
        } else {
            System.out.println("Person not found.");
        }
    }

    public void viewRelationships() {
        for (Relationship relationship : relationships) {
            String person1Name = relationship.getPerson1().getName();
            String person2Name = relationship.getPerson2().getName();
            String relationshipType = relationship.getRelationshipType();

            System.out.println(person1Name + " - " + relationshipType + " - " + person2Name);
        }
    }

    public void searchRelationships(String personName) {
        List<Relationship> foundRelationships = new ArrayList<>();

        for (Relationship relationship : relationships) {
            if (relationship.getPerson1().getName().equals(personName)
                    || relationship.getPerson2().getName().equals(personName)) {
                foundRelationships.add(relationship);
            }
        }

        if (!foundRelationships.isEmpty()) {
            System.out.println("Relationships involving " + personName + ":");
            for (Relationship relationship : foundRelationships) {
                String person1Name = relationship.getPerson1().getName();
                String person2Name = relationship.getPerson2().getName();
                String relationshipType = relationship.getRelationshipType();

                System.out.println(person1Name + " - " + relationshipType + " - " + person2Name);
            }
        } else {
            System.out.println("No relationships found for " + personName);
        }
    }

    private Person findPerson(String name) {
        for (Person person : people) {
            if (person.getName().equals(name)) {
                return person;
            }
        }
        return null;
    }

    public static void main(String[] args) {
        RelationshipManager manager = new RelationshipManager();
        Scanner scanner = new Scanner(System.in);

        while (true) {
            System.out.println("Relationship Manager");
           

Post a Comment

0 Comments

•Give The opportunity to your child with GreatToCode Kid's • Online Coding Classes for Your Kid • Introduce Your kid To the world's of coding
•Fuel You Career with our 100+ Hiring Partners, Advance Your Career in Tech with GreatToCode. •Join The Largest Tech and coding Community and Fast Forward Your career with GreatToCode. •10000+ Learner's+ 90 % placement Guarantee. • Learning Coding is Better with the GreatToCode community .
•Greattocode Kid's •GreatToCode Career •GreatToCode Interview •GreatToCode Professional •GreatToCode for schools •GreatToCode For colleges •GreatToCods For Businesses.
Are you ready to join the millions of people learning to code? GreatToCode Pass is your one-stop-shop to get access to 1000+ courses, top-notch support, and successful job placement. What are you waiting for? Sign up now and get your future in motion with GreatToCode Pass.