Can this code be rewritten but keeping the same functions as the original and with detailed comments. I'm going to post the original homework lab just in case.
Attached to this assignment is a Java program that converts a text file to a list of hexadecimal numbers. Each of those hexidecimal numbers represents the bit pattern of a character from the file with the parity bits (even parity) for a hamming code inserted. Each text character takes 8 bits and the hamming code adds 4 bits. This hamming code provides single-bit error correction. Requirements 1. The program must be written in Java. If you have not used Java before, you can learn it enough to do this assignment, by looking at the provided program. 2. You can use Eclipse to write, compile and test your program, but you may also use any other development environment you like. Only the .java file will be submitted. 3. The program will use the provided Hamming class. It will implement the decode function. The decode function is the reverse of the encode function, but it also performs single bit correction when necessary. 4. Display a message to the console when an error is corrected, as in the example below. 5. The main function must be rewritten to read hexidecimal numbers from hamming.txt file and write decoded and corrected text to output.txt. 6. Test the program with different input files. The instructor will test it with a hamming.txt file different from the one provided.
import java.io.*;
import java.util.*;
public class Hamming
{
private char letter;
private int[] bits = new int[12];
private int code;
public Hamming(char let) { letter = let; encode(); }
public Hamming(int c) { code = c; decode(); }
public int getCode() { return code; }
public char getLetter() { return letter; }
private void encode() {
int value = letter;
for (int i = 0; i < 12; i++) {
if (i != 0 && i != 1 && i != 3 && i != 7) {
bits[i] = value % 2;
value /= 2;
}
}
bits[0] = bits[2] ^ bits[4] ^ bits[6] ^ bits[8] ^ bits[10]; // ^ is XOR in Java
bits[1] = bits[2] ^ bits[5] ^ bits[6] ^ bits[9] ^ bits[10];
bits[3] = bits[4] ^ bits[5] ^ bits[6] ^ bits[11];
bits[7] = bits[8] ^ bits[9] ^ bits[10] ^ bits[11];
code = 0;
for (int i = 11; i >= 0; i--) {
code *= 2;
code += bits[i];
}
}
private void decode() {
int error = 0;
int value = code;
for (int i = 0; i < 12; i++) {
bits[i] = value % 2;
value /= 2;
}
if (bits[0] != (bits[2] ^ bits[4] ^ bits[6] ^ bits[8] ^ bits[10])) error += 1;
if (bits[1] != (bits[2] ^ bits[5] ^ bits[6] ^ bits[9] ^ bits[10])) error += 2;
if (bits[3] != (bits[4] ^ bits[5] ^ bits[6] ^ bits[11])) error += 4;
if (bits[7] != (bits[8] ^ bits[9] ^ bits[10] ^ bits[11])) error += 8;
if (error != 0)
bits[error - 1] ^= 1;
letter = 0;
for (int i = 11; i >= 0; i--) {
if (i != 0 && i != 1 && i != 3 && i != 7) {
letter *= 2;
letter += bits[i];
}
}
if (error != 0)
System.out.println("Error in bit " + (error - 1) + " corrected in character " + letter);
}
public static void main(String[] args) throws FileNotFoundException
{
Scanner inFile = new Scanner( new File("hamming.txt"));
PrintStream outFile = new PrintStream(new File("output.txt"));
String line;
int code;
System.out.println("File hamming.txt opened");
while (inFile.hasNextInt(16)) {
code = inFile.nextInt(16);
Hamming ham = new Hamming(code);
outFile.print(ham.getLetter());
}
inFile.close();
System.out.println("File output.txt closed");
}
}
In: Computer Science
1. Suppose that you have ten cards. Five are red, three are yellow and two are blue. The five red cards are numbered 1, 2, 3, 4, and 5. The three yellow cards are numbered 1, 2, and 3. The two blue cards are numbered 1 and 3. The cards are well shuffled. You randomly draw one card. Let R be the event that the card drawn is red and O be the event that the card drawn is odd-numbered. Find Pr(R|O).
2. Suppose you flip two fair coins simultaneously. Let A and B denote respectively the event of getting a head for the first coin and the event of getting a tail for the second coin. Which of the following statements do you think is incorrect?
| A. |
The events A and B are mutually independent. |
|
| B. |
Pr(A) + Pr(B) = 1. |
|
| C. |
Pr(A or B) = 3/4. |
|
| D. |
The events A and B are mutually exclusive. |
3. Suppose A and B are two mutually independent events such that Pr(A)=1 and Pr(B)=1. Which of the following statements is incorrect?
| I. |
Pr(A|B)=Pr(A). |
|
| II. |
Pr(A or B)=1. |
|
| III. |
Pr(A and B)=1. |
|
| IV. |
Pr(A or B) = Pr(A) + Pr(B). |
4. Suppose A and B are two mutually exclusive events with Pr(A)=0.5 and Pr(B)=0.5. Which of the following statements do you think is correct?
| I. |
Pr(A|B)=Pr(A). |
|
| II. |
Pr(B|A)=Pr(B). |
|
| III. |
Pr(A and B)=0.5. |
|
| IV. |
Pr(A or B) = 1. |
5. Suppose J and K are two independent events such that Pr(J|K) = 0.37.
Find P(J'), where J' denotes the complement of event J.
In: Statistics and Probability
Coyote Manufacturing bought a machine for $90,000 on April 1, 2018. To install the machine Coyote Manufacturing spent $10,000. It was estimated that the useful life be 4 years or 1,000,000 machine-hours. And the residual value at the end of the useful life be $4,000. Number of hours that the machine has been used or will be used are as follows: 2018 2019 2020 2021 2022 70,000 hours 240,000 290,000 230,000 170,000 Instructions: 1. Prepare journal entries for the purchase of the truck on April 1, 2018. 2. Compute depreciation expenses on the machine for the years ending on December 31 of 2018 and 2019 using following methods; 1) Straight-line method, 2) Activity based method, 3) Sum-of-the-years'-digit, 4) Double declining method. 3. Coyote sold this machine for $50,000 on January 1, 2020 - Prepare any necessary journal entries for this sale using Sum-of-years’-digit method
In: Accounting
Consider the following Ricardian model.
MPL Labor Supply
Pens Pencils
France 1/10 1/15 90
Germany 1/12 1/20 120
Answer the following questions and show your steps. For the T/F questions, please explain why they are T/F.
1. Draw the PPF for France. Label your picture, and calculate the slope of the PPF, (4 points)
2. France has the absolute advantage in both goods.
3. France has the comparative advantage in pens.
4. If the labor supply increases in France, France is more likely to have a comparative advantage in pencils since the production of pencils requires more labor.
5. In moving from closed-economy to free trade, France produces fewer pens.
6. Under free trade, the relative price of pens to pencils (PpensT/PpencilsT) cannot exceed 2/3.
Don't copy others please, they all did wrong answers.
In: Economics
A research study was conducted to examine the impact of eating a high protein breakfast on adolescents' performance during a physical education physical fitness test. The students were randomly selected and half received a high protein breakfast and half a low protein breakfast. All of the adolescents, both male and female, were given a fitness test with high scores representing better performance. Test scores are recorded below.
|
Group |
High Protein |
Low Protein |
|
Males |
9 8 |
7 5 |
|
Females |
5 4 |
3 1 |
Compute Levene’s Test of Equality of Error Variances and ANOVA Source Table.
Is the main effect for Protein Level significant? – 5 points.
Is the main effect for Gender significant? – 5 points.
Graph the interaction of Protein Level and Gender – (10 points).
Write one paragraph summarizing the results and explaining the findings. – (10 points).
In: Statistics and Probability
A research study was conducted to examine the impact of eating a high protein breakfast on adolescents' performance during a physical education physical fitness test. The students were randomly selected and half received a high protein breakfast and half a low protein breakfast. All of the adolescents, both male and female, were given a fitness test with high scores representing better performance. Test scores are recorded below.
|
Group |
High Protein |
Low Protein |
|
Males |
9 8 |
7 5 |
|
Females |
5 4 |
3 1 |
Compute Levene’s Test of Equality of Error Variances and ANOVA Source Table.
Is the main effect for Protein Level significant? – 5 points.
Is the main effect for Gender significant? – 5 points.
Graph the interaction of Protein Level and Gender – (10 points).
Write one paragraph summarizing the results and explaining the findings. – (10 points).
In: Statistics and Probability
St= β0 + β1 (St-1) + β2 (St-2) + β3 (St -3) + β4 (St-4) + .
Our OLS-estimated model is given below. Numbers in the parentheses under the coefficients are p-valuesfor the corresponding parameter estimation. Significance level=5%.
= 5.60 1.05St-1 0.57St-2 0.32St-3 0.051St-4
(0.3) (0.006) (0.32) (0.040) (0.562)
N=36 R2= 0.55 Adj- =0.53 Coefficient Var=1.57
|
Years |
M&M Sales (100 million dollars) |
|
2013 |
5.8 |
|
2014 |
6.5 |
|
2015 |
7 |
|
2016 |
7.1 |
|
2017 |
7.5 |
In: Statistics and Probability
A study is conducted to determine the relationship between a driver's age and the number of accidents he or she has over a 1-year period. The data are shown here. If there is a significant relationship, predict the number of accidents of a driver who is 28.
| Driver's | No. of |
| Age x | accidents y |
| 16 | 3 |
| 24 | 2 |
| 18 | 5 |
| 17 | 2 |
| 23 | 0 |
| 27 | 1 |
| 32 | 1 |
1. What is your alternative hypothesis (H1)?
2. Compute the value of the correlation coefficient.
3. Determine the regression equation line even if the equation is not valid.
4. Test the significance of the correlation coefficient and the regression equation at a level of significance of .01.
In: Statistics and Probability
Use Laplace transformations to solve the following differential equations:
dy(t)/dt + a y(t) = b; I.C.s y(0) = c
d2y(t)/dt2 + 6 dy(t)/dt + 9 y(t) = 0; I.C.s y(0) = 2, dy(0)/dt = 1
d2y(t)/dt2 + 4 dy(t)/dt + 8 y(t) = 0; I.C.s y(0) = 2, dy(0)/dt = 1
d2y(t)/dt2 + 2 dy(t)/dt + y(t) = 3e-2t; I.C.s y(0) = 1, dy(0)/dt = 1
In: Mechanical Engineering
1. Market demand and supply for a commodity are given by the following equations:
Demand: X = 30 – (1/3) P Supply: X = -2.5 + (1/2) P where X= quantity (units), and P=price per unit ($)
Suppose that the government is planning to impose a tax on this commodity and considering the following two options:
Option 1: A unit tax of $15
Option 2: An ad valorem tax of 20%
In: Economics