Question
do the following java program so that it reads and output the code using a text file to read theirs instuctions inside the code heres
do the following java program so that it reads and output the code using a text file to read theirs instuctions inside the code
heres a example of the textfile in order put them in a text file and have the program read and then it should solve it
ABCDEF AB C BC AD D E CF B
// DB5.java CS5151/6051 2020 Cheng
// Algorithm 3.7 closure of X under F
// Usage: java DB5 F
// F is a file that has the first line all the attributes and
// then an FD a line with a space between the left-hand side and the right-hand
side
// A set enumeration algorithm is used to go through all subsets of attributes
// closure, nontrivial FDs, and whether the subset is a superkey are displayed
// recursive calls in set enumeration SE stops if closure is all attributes
import java.io.*;
import java.util.*;
public class DB5{
class FD{
HashSet
public FD(HashSet
public boolean equals(Object obj){
FD fd2 = (FD)obj;
return lhs.equals(fd2.lhs) && rhs == fd2.rhs;
}
};
HashSet
HashSet
HashSet
public DB5(String filename){ // 1. split FDs so each FD has a single attribute
on the right
Scanner in = null;
try {
in = new Scanner(new File(filename));
} catch (FileNotFoundException e){
System.err.println(filename + " not found");
System.exit(1);
}
String line = in.nextLine();
for (int i = 0; i < line.length(); i++) R.add(line.charAt(i));
while (in.hasNextLine()){
HashSet
String[] terms = in.nextLine().split(" ");
for (int i = 0; i < terms[0].length(); i++)
l.add(terms[0].charAt(i));
for (int i = 0; i < terms[1].length(); i++) F.add(new FD(l,
terms[1].charAt(i)));
}
in.close();
}
HashSet
X = new HashSet
int len = 0;
do { // 3. push out
len = X.size();
F.forEach(fd -> {
// your code for step 3 of Algorithm 3.7
// if all of fd.lhs are in X, but fd.rhs is not, then add fd.rhs
to X.
// should be an if-then statement with ending ;
// Hint: HashSet
});
} while (X.size() > len);
return X; // 4. found closure of X
}
void SE(HashSet
if (handleSubset(subset)) return;
HashSet
view.forEach(c -> {
newView.remove(c);
subset.add(c);
SE(new HashSet
subset.remove(c);
});
}
boolean handleSubset(HashSet
System.out.print("\"");
subset.forEach(x -> System.out.print(x));
System.out.print("\",\"");
HashSet
boolean superkey = clo.size() == R.size();
clo.forEach(x -> System.out.print(x));
System.out.print("\"");
clo.removeAll(subset);
if (clo.size() > 0){
System.out.print(",");
subset.forEach(x -> System.out.print(x));
System.out.print("->");
clo.forEach(x -> System.out.print(x));
}
if (superkey) System.out.println(" superkey"); else System.out.println();
return superkey;
}
void closuresToAll(){
System.out.println("Subset,Closure,Nontrivial FDs");
SE(R, new HashSet
}
public static void main(String[] args){
DB5key db5 = new DB5key(args[0]);
db5.closuresToAll();
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started