Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

8, Question: (10 points) In \"chefmozhours4.csv” , the \"days\" column is a cate

ID: 3592906 • Letter: 8

Question

8, Question: (10 points) In "chefmozhours4.csv” , the "days" column is a categorical attribute with values from [Mon;Tue;Wed;Thu;Fri;Sat;Sun]. Here are some sample values of the "days" column davs Mon;Tue;Wed;Thu;Fri; Sat; Sun; Please create seven columns (namely Mon, Tue, Wed, Thu, Fri, Sat, Sun) in "chefmozhours4.csv” . Each of the seven columns is a binary attribute (0 or 1), where 0 represents the restaurant will close on that day, and 1 represents the restaurant will open on that day. For instance, the above example can be converted into: Mon Tue Wed Thu ri Sun 0 0 0 0 0 0 0

Explanation / Answer

Java code:

import java.io.BufferedReader;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;

/**
*
* @author Sam
*/
public class RetaurantScheduler {
    public static void main(String[] args) throws FileNotFoundException, IOException {
        BufferedReader br = new BufferedReader(new FileReader("chetmozhours4.csv"));
        PrintWriter pw = new PrintWriter("chefmozhours4.csv");
        String line;
        br.readLine();
        String dayNames[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
        for (int i = 0; i < 7; i++)
            pw.print(dayNames[i]+";");
        pw.println();
        while ((line = br.readLine())!=null) {
            String[] days = line.split(";");
            for (String day:days)
                for (int i = 0; i < 7; i++)
                    if (day.equalsIgnoreCase(dayNames[i]))
                        pw.print("1;");
                    else
                        pw.print("0;");
            pw.println();
        }
        pw.close();
    }  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote