Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

need help with what is wrong with my code? import java.io.File; import java.io.FileNotFoundException; // Import this class to handle errors import java.util.Scanner; class Relation {

need help with what is wrong with my code?

import java.io.File;

import java.io.FileNotFoundException; // Import this class to handle errors

import java.util.Scanner;

class Relation {

// This method returns if matrixrix is reflexive or not

public static Boolean isReflexive(int matrix[][],int n){

for(int i=0;i

if(matrix[i][i]!=1)

return false;

}

return true;

}

// This method returns if matrixrix is antireflexive or not

public static Boolean isAntiReflexive(int matrix[][],int n){

for(int i=0;i

if(matrix[i][i]!=0)

return false;

}

return true;

}

// This method returns if matrixrix is symmetric or not

public static Boolean isSymmetric(int matrix[][],int n){

for(int i=0;i

for(int j=0;j

if(i==j)

continue;

if(matrix[i][j]!=matrix[j][i])

return false;

}

}

return true;

}

// This method returns if matrixrix is antisymmetric or not

public static Boolean isAntiSymmetric(int matrix[][],int n){

for(int i=0;i

for(int j=0;j

if(i==j)

continue;

if(matrix[i][j]==matrix[j][i])

return false;

}

}

return true;

}

public static void main(String[] args) {

// Reading file name from user

System.out.print("File input: ");

Scanner sc = new Scanner(System.in);

String file_name = sc.nextLine();

sc.close();

// try to open and read file

try {

File myObj = new File(file_name);

Scanner user = new Scanner(myObj);

int matrix[][] = new int[10][10];

int i=0;

// reading the file and filling matrix

while (user.hasNextLine()) {

String data = user.nextLine();

for(int j=0;j

matrix[i][j] = Integer.parseInt(data.split(" ")[j]);

}

i++;

}

// Displaying all the output

System.out.println("Reflexive - " + (isReflexive(matrix, 10) ? "yes" : "no"));

System.out.println("AntiReflexive - " + (isAntiReflexive(matrix, 10) ? "yes" : "no"));

System.out.println("Symmetric - " + (isSymmetric(matrix, 10) ? "yes" : "no"));

System.out.println("Antisymmetric - " + (isAntiSymmetric(matrix, 10) ? "yes" : "no"));

user.close();

} catch (FileNotFoundException e) { // if error occurred while opening the file

System.out.println("An error occurred.");

e.printStackTrace();

}

}

}image text in transcribedimage text in transcribed

Output Your program should output statements that claim the existence or violation of each property. A sample program output is given below. File input: matrix5.txt Reflexive - yes Antireflexive Symmetric - yes Antisymmetric yes no Test cases Matrix1.txt 1 1 1 0 1 0 0 1 1 o o o 1 1 1 1 1 oo 1 1 1 1 POOP Matrix2.txt oo 1 1 0 1 0 1 1 1 0 1 0 0 0 1 0 1 0 1 0 0 1 1 0 1 0 oo 1 o 1 1 0 1 0 1 0 0 1 1 0 1 1 0 1 0 1 1 o 1 1 1 1 1 1 1 0 0 1 0 1001001001 RO Matrix3.txt Search documents and file 0 1 1 1 1 0 1 0 1 1 0 1 1 0 0 1 1 o o o 1 oo 1 1 1 0 0 0 oo 1 o 1 o 1 0 1 1 1 1 1 1 1 1 0 1 1 1 0 0 1 oo 1 0<>

<>

<>

<>

<>

<>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions