Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

using the code below fill in the question marks in the coding using java also have the following code pull information from a file called

using the code below fill in the question marks in the coding using java also have the following code pull information from a file called im sure you call the file somewhere in the main but not entirely sure.

example3_23.txt

the contents of the text file is as follows

ABCD A B B C CD A

import java.io.*; import java.util.*;

public class DB7{

class FD{ HashSet lhs; char rhs; public FD(HashSet l, char r){ lhs = l; rhs = r; } public boolean equals(Object obj){ FD fd2 = (FD)obj; return lhs.equals(fd2.lhs) && rhs == fd2.rhs; } public void print(){ lhs.forEach(c -> System.out.print(c)); System.out.println(" " + rhs); } };

HashSet R = new HashSet(); // all attributes HashSet F = new HashSet(); // the set of FDs int[][] tableau = null; int rows = 0; int cols = 0; char[] attributes = null; HashMap att2col = new HashMap(); int n = 0; int m = 0; int l = 0; boolean changed = false;

public DB7(String[] args){ // 1. split FDs so each FD has a single attribute on the right Scanner in = null; try { in = new Scanner(new File(args[0])); } catch (FileNotFoundException e){ System.err.println(args[0] + " not found"); System.exit(1); } String line = in.nextLine(); cols = line.length(); attributes = new char[cols]; for (int i = 0; i < cols; i++){ attributes[i] = line.charAt(i); R.add(attributes[i]); att2col.put(attributes[i], i); } while (in.hasNextLine()){ HashSet l = new 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(); rows = args.length - 1; tableau = new int[rows][cols]; for (int i = 0; i < rows; i++){ for (int j = 0; j < cols; j++) tableau[i][j] = i; for (int j = 0; j < args[i + 1].length(); j++) tableau[i][att2col.get(args[i + 1].charAt(j))] = -1; // -1 is for unsubscripted components (in attribute set Si, see 3.4.2) } printTableau(); }

void printTableau(){ for (int i = 0; i < cols; i++) System.out.print(attributes[i] + "\t"); System.out.println(); for (int i = 0; i < rows; i++){ for (int j = 0; j < cols; j++) System.out.print(tableau[i][j] + "\t"); System.out.println(); } System.out.println(); }

void chase(){ // Your code needed do { changed = false; F.forEach(fd -> { fd.print(); for (m = 1; m < rows; m++) for (l = 0; l < m; l++){ n = 0; fd.lhs.forEach(c -> { int col = att2col.get(c); if (tableau[m][col] == tableau[l][col]) n++; }); if (n == fd.lhs.size()){ // tuples m and l agree on all shared attributes int col = att2col.get(fd.rhs); // they should also agree on col if (tableau[m][col] != tableau[l][col]){ if (tableau[m][col] == -1) tableau[l][col] = ???; else if (tableau[l][col] == -1) tableau[m][col] = ???; else tableau[m][col] = ???; changed = true; printTableau(); } } } }); } while (changed == true); }

void conclusion(){ // Your code to idensity whether the decomposition is lossless if (???) System.out.println("lossless"); else System.out.println("not lossless"); }

public static void main(String[] args){ if (args.length < 3){ System.err.println("Usage: java DB7 FDs schema1 schema2 ..."); return; } DB7 db7 = new DB7(args); db7.chase(); db7.conclusion(); } }

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

Students also viewed these Databases questions

Question

Why does sin 2x + cos2x =1 ?

Answered: 1 week ago

Question

What are DNA and RNA and what is the difference between them?

Answered: 1 week ago

Question

Why do living creatures die? Can it be proved that they are reborn?

Answered: 1 week ago

Question

3. Identify challenges to good listening and their remedies

Answered: 1 week ago

Question

4. Identify ethical factors in the listening process

Answered: 1 week ago