THIS IS MY CODE
i tried to do it but i couldn't
Write a program to read 2 students full names starting with first then fathers name then family , (separated by blanks , e.g : ashelly joe daniel ), then :
• If these two students have same full names display ( These are duplicate names) .
• If they are brothers display (They are brothers or sisters)
• If they are only from same family , display (They are relatives)
• If none of the above , display (May be , they are just friends).
Note : find a way to avoid case-sensitivity, because some will enter names capital or small letters , but for us it should be the same. ( ashelly == ASHELLY)
Code:import java.util.*;
public class MARC
{
static Scanner console = new Scanner(System.in);
public static void main(String [] args)
{
String name1, name2;
int apos1, apos2, rpos1, rpos2;
String first, second, father1, father2, family1, family2;
System.out.println("enter first name: ");
name1 = console.nextLine();
System.out.println("enter second name: ");
name2 = console.nextLine();
apos1 = name1.indexOf(' ');
apos2 = name1.indexOf(' ', apos1);
rpos1 = name2.indexOf(' ');
rpos2 = name2.indexOf(' ', rpos1);
first = name1.substring(0, apos1);
father1 = name1.substring(apos1+1,apos2+1);
family1 = name1.substring(apos2);
second = name2.substring(0, rpos1);
father2 = name2.substring(rpos1+1, rpos2+1);
family2 = name2.substring(rpos2);
if
(first.equals(second))
{
if
(father1.equals(father2))
if
(family1.equals(family2))
System.out.println("These are duplicate names");
else if
(first.equals(second))
if
(father1.equals(father2))
if
(family1.equals(family2))
System.out.println("They are brothers or sisters");
else if
(family1.equals(family2))
System.out.println("They are relatives");
}
else
System.out.println("May be , they are just friends");
}}
