So i had to write a program that uses these functions to add, subtract, multiply and see if the numbers equal each other. and also You must create a way to keep track of the relationships between friends, the spouses, the siblings, the children of the men and women. attached is the requirements.

import java.util.Scanner;
public class lhlFamily {


    char[][] mem=new char[100][100];
    int cnt;
    public  lhlFamily()
    {
        Scanner key = new Scanner(System.in);
        System.out.println("Enter count of members");
        cnt=Integer.parseInt(key.nextLine());
        int i,j,k;
        for(i=0;i<cnt;i++)
        {
            for(j=i+1;j<cnt;j++)
            {
                System.out.println("Enter relationship of "+i+" and "+j+" Enter 'n' if not directly connected");
                String r=key.nextLine();
                mem[i][j]=r.charAt(0);

            }
        }

    }
    int plus(int x,int y)
    {
        return (x+y);
    }
    int minus(int x,int y)
    {
        return (x-y);
    }
    int times(int x,int y)
    {
        return (x*y);
    }
    boolean equals(int x,int y)
    {
        if(x==y)
            return true;
        else
            return false;
    }
    boolean friend(int x,int y)
    {
        if(x<y)
        {
            if(mem[x][y]=='f')
                return true;
            else
                return false;
        }
        else
        {
            if(mem[y][x]=='f')
                return true;
            else
                return false;
        }

    }
    void friends(int x)
    {
        int i=0;
        System.out.print("Friends of "+x+" are ");
        for(i=1;i<x;i++)
        {
            if(mem[i][x]=='f')
                System.out.print(i+"\t");
        }
        for(i=x+1;i<cnt;i++)
        {
            if(mem[x][i]=='f')
              System.out.print(i+"\t");
        }
        System.out.print("\n");
    }
    boolean father(int x,int y)
    {
        boolean f=false;
        if(mem[x][y]=='f'||mem[y][x]=='f')
            return true;
        else
        {
        int i,mother=0;
        for(i=1;i<x;i++)
        {
            if(mem[i][x]=='m')
            {
                mother=i;
                break;
            }
        }
        if(mother==0)
        {
           for(i=x+1;i<cnt;i++)
           {
               if(mem[x][i]=='m')
               {
                   mother=i;
                   break;
               }
           }
        }
        for(i=1;i<mother;i++)
        {
            if(mem[i][mother]=='h'&&i==y)
            {
                f=true;
                break;
            }
        }
        if(!f)
        {
           for(i=mother+1;i<cnt;i++)
           {
               if(mem[mother][i]=='h'&&i==y)
               {
                   f=true;
                   break;
               }
           }

        }
        return f;
        }
    }
    boolean mother(int x,int y)
    {
        boolean m=false;
        if(mem[x][y]=='m'||mem[y][x]=='m')
            return true;
        else
        {
        int i,father=0;
        for(i=1;i<x;i++)
        {
            if(mem[i][x]=='f')
            {
                father=i;
                break;
            }
        }
        if(father==0)
        {
           for(i=x+1;i<cnt;i++)
           {
               if(mem[x][i]=='f')
               {
                   father=i;
                   break;
               }
           }
        }
        for(i=1;i<father;i++)
        {
            if(mem[i][father]=='w'&&i==y)
            {
                m=true;
                break;
            }
        }
        if(!m)
        {
           for(i=father+1;i<cnt;i++)
           {
               if(mem[father][i]=='w'&&i==y)
               {
                   m=true;
                   break;
               }
           }

        }
        return m;
        }
    }
    boolean sibling(int x,int y)
    {
        if(mem[x][y]=='s'||mem[y][x]=='s')
           return true;
        else
            return false;
    }

    public static void main(String[] args) {

        Family f=new Family();
        int x,y;
        Scanner key = new Scanner(System.in);
        System.out.println("Enter 2 numbers which need to be checked for friend relation");
        x=Integer.parseInt(key.nextLine());
        y=Integer.parseInt(key.nextLine());
        System.out.println("The friend relationship between "+x+" and "+y+" is "+f.friend(x,y));
        System.out.println("Enter a number whose friends need to be displayed");
        x=Integer.parseInt(key.nextLine());
        f.friends(x);
        System.out.println("Enter 2 numbers which need to be checked for father relation");
        x=Integer.parseInt(key.nextLine());
        y=Integer.parseInt(key.nextLine());
        System.out.println("The father relationship between "+x+" and "+y+" is "+f.father(x,y));
        System.out.println("Enter 2 numbers which need to be checked for mother relation");
        x=Integer.parseInt(key.nextLine());
        y=Integer.parseInt(key.nextLine());
        System.out.println("The mother relationship between "+x+" and "+y+" is "+f.mother(x,y));
        System.out.println("Enter 2 numbers which need to be checked for sibling relation");
        x=Integer.parseInt(key.nextLine());
        y=Integer.parseInt(key.nextLine());
        System.out.println("The sibling relationship between "+x+" and "+y+" is "+f.sibling(x,y));

    }

}

Recommended Answers

All 4 Replies

Eh? I don't really understand what you want here, sorry. There is a list below about why I don't understand you.

1) Are you trying to solve 1 or 2 problems in the same program? I don't see any relationship between arithmetic and friend/sibling/etc?

2) Why did you upload the attached file? Besides, the file is in MS Word 2007 version. I can't and won't open it because I am using Linux...

3) What is actually your problem? Errors in your program? If so, what are they? And how did you produce the errors?

no its suppsoe to be 12 problems in the same program its asking to do a comparison between friends if they are friends, atleast 1 is a friend etc; before that your suppsoe to enter two numbers to do the mathematical part thats a separate part, and then the family component which is also separate you can do liek a choice type thing to select what part to do. my error is when i go to run the program it asks me to enter 2 numbers to make the friend comparison when its suppsoe to let me enter the members name first and then do it.

Eh? I don't really understand what you want here, sorry. There is a list below about why I don't understand you.

1) Are you trying to solve 1 or 2 problems in the same program? I don't see any relationship between arithmetic and friend/sibling/etc?

2) Why did you upload the attached file? Besides, the file is in MS Word 2007 version. I can't and won't open it because I am using Linux...

3) What is actually your problem? Errors in your program? If so, what are they? And how did you produce the errors?

This project utilizes the predicate and propositional calculus functions in chapter two. Your project must contain at least the functions listed below. You must create a way to keep track of the relationships between friends, the spouses, the siblings, the children of the men and women.

Eh? I don't really understand what you want here, sorry. There is a list below about why I don't understand you.

1) Are you trying to solve 1 or 2 problems in the same program? I don't see any relationship between arithmetic and friend/sibling/etc?

2) Why did you upload the attached file? Besides, the file is in MS Word 2007 version. I can't and won't open it because I am using Linux...

3) What is actually your problem? Errors in your program? If so, what are they? And how did you produce the errors?

the program is suppose to just add, subtract, multiply and see if
(2,2) are equal or (2,Plus(2,3)) are eual. for the first part then the
other part is the friends then the father,mother, sibling part. here is an example of how my classmates did there form but i wanted to go a different route :example
1) plus 2)minus 3)times 4)equals 5)friend 6)friends 7)atleast 1 is a
friend of 8)all are friends of 9)father(x,y) 10)mother(x,y)
11)siblings(x,y) 12)siblings
if(choice==1) {system.out.println("enter the first number:") x=
console.nextInt(); ETC.

no its suppsoe to be 12 problems in the same program its asking to do a comparison between friends if they are friends, atleast 1 is a friend etc; before that your suppsoe to enter two numbers to do the mathematical part thats a separate part, and then the family component which is also separate you can do liek a choice type thing to select what part to do. my error is when i go to run the program it asks me to enter 2 numbers to make the friend comparison when its suppsoe to let me enter the members name first and then do it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.