Question

**I asked this question once, and the answer completely ignored a majority of the rules listed...

**I asked this question once, and the answer completely ignored a majority of the rules listed on this. PLEASE read what is necessary before giving an answer.

**NEITHER answer when searching for this question has a ParityChain class, a ParityChainDemo class or even include some of the stated requirements (such as hasError method).

**Parity bit was specified by instructor to be LEFT most bit in chain

Done in Java using Apache NetBeans IDE 11.2 -- Objectives: To create a data structure with underlying linked chain; To utilize and implement code dealing with parity big codes for error detection; To read data from file

**The other answer when searching for this question does not have a ParityChain class, a ParityChainDemo class or even include some of the stated requirements (such as hasError method).

**Parity bit was specified by instructor to be LEFT most bit in chain

In this project, you will read bits (0s and 1s) from a file. On each line there will be 8 bits. You must read them into memory and store each bit in a node in a linked chain.

We will use an error detection technique called parity bits. We will specifically use even parity. So, 7 bits represent data and one bit represents the parity. What this means is if there are, for example, an odd number of 1s in the actual data, the parity bit (first bit) is set to 1 to make the number of 1s even. If there is an even number of 1s in the actual data, then we set the parity bit (first bit) to 0.

We know there is an error if the byte (8 bits) we receive ever has an odd number of ones in it, because there should be an even number.

So the input on a single line might contain the following:

0 1 1 1 1 1 0 1

Since we read this and found six 1s, this byte is assumed to be error free (in our scheme.)

But if we read the following:

1 1 1 0 1 1 1 1

By the time we get it, there are seven 1s, so that’s an odd number of 1s. This means there must be an error somewhere.

Your assignment does not require you to fix the errors. However, your ParityChain class must know if it has an error or not (hasError method, which returns true or false). Also, you should be able to tell the chain to print out its bits.

You must read an arbitrary number of bytes (lines of 8 bits with spaces in between) from file. Each “firstNode” may be placed into an ArrayList, but the enter chain itself must be linked, and made manually by you (with nodes.)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Problem statement:

Your assignment does not require you to fix the errors. However, your ParityChain class must know if it has an error or not (hasError method, which returns true or false). Also, you should be able to tell the chain to print out its bits.

You must read an arbitrary number of bytes (lines of 8 bits with spaces in between) from file. Each “firstNode” may be placed into an ArrayList, but the enter chain itself must be linked, and made manually by you (with nodes.)

Explanation:

A Node.java class has been created for each bit of the byte. An arraylist is used to keep track of the arbitrary number of bytes that have to be read from the file.

The implementation for the linked node is there in the StackLinkedList.java class. It also calculates and error in the method hasError method, which returns true or false.

For the sake of test a file input.txt has been used.

The java classes and the input file and the outputs have been given below. Please feel free to reach out if you have questions.

Java classes

##############################################################################

Node.java

public class Node {

   int data;

   Node link;

   public Node () {

   }

   public Node(int data, Node link) {

   this.data = data;

   this.link = link;

   }

}

##############################################################################

StackLinkedList.java

public class StackLinkedList {

Node top;

StackLinkedList() {

   this.top = null;

}

public void push(int x) {

   Node node = new Node();

   node.data = x;

   node.link = top;

   top = node;

}

public boolean isEmpty() {

   return top == null;

}

public int peek() throws Exception {

   if (!isEmpty()) {

   return top.data;

   }

   else {

   throw new Exception();

   }

}

public void pop() {

   if (top == null) {

   System.out.print("\nStack Underflow");

   return;

   }

   top = (top).link;

}

public void displayChain() {

   if (top == null) {

   System.out.println("[]");

   }

   else {

   Node temp = top;

   String str = "[";

   while (temp != null) {

   str += temp.data + ", ";

   temp = temp.link;

   }

   str = str.trim();

   str = str.substring(0,str.length()-1);

   str += "]";

   System.out.println(str);

   }

}

public int size() {

int count = 0;

Node temp = top;

   while (temp != null) {

   temp = temp.link;

   count++;

   }

return count;

}

public boolean hasError() {

int count = 0;

Node temp = top;

   while (temp != null) {

   if(temp.data == 1)

   count++;

   temp = temp.link;

   }

return count%2 == 1;

}

}

##############################################################################

ParityChain.java

import java.io.File;

import java.io.IOException;

import java.util.ArrayList;

import java.util.Scanner;

public class ParityChain {

static ArrayList<StackLinkedList> list = new ArrayList<StackLinkedList>();

public static void main(String[] args) throws IOException {

File file = new File("input.txt");

Scanner sc = new Scanner(file);

while (sc.hasNextLine()) {

String input = (sc.nextLine());

StackLinkedList stack = new StackLinkedList();

for(int i=0;i<input.length();i++) {

if(input.charAt(i) != ' ') {

stack.push(Integer.parseInt(String.valueOf(input.charAt(i))));

}

}

list.add(stack);

}

displayErrors();

}

public static void displayErrors() {

for(int i = 0; i<list.size(); i++) {

StackLinkedList linkedList = list.get(i);

linkedList.displayChain();

System.out.println("Does bytes have error : " + linkedList.hasError() + "\n");

}

}

}

Input file

##############################################################################

input.txt

0 1 1 1 1 1 0 1

1 1 1 0 1 1 1 1

1 1 0 0 1 1 1 1

1 1 1 1 1 1 1 1

1 0 1 0 1 0 1 1

0 1 0 0 1 0 1 1

##############################################################################

Output:

[1, 0, 1, 1, 1, 1, 1, 0]

Does bytes have error : false

[1, 1, 1, 1, 0, 1, 1, 1]

Does bytes have error : true

[1, 1, 1, 1, 0, 0, 1, 1]

Does bytes have error : false

[1, 1, 1, 1, 1, 1, 1, 1]

Does bytes have error : false

[1, 1, 0, 1, 0, 1, 0, 1]

Does bytes have error : true

[1, 1, 0, 1, 0, 0, 1, 0]

Does bytes have error : false

##############################################################################

Screenshots:

A Problems @ Javadoc Declaration Console X <terminated> Parity Chain [Java Application] /Library/Java/JavaVirtual Machines/jd

Add a comment
Know the answer?
Add Answer to:
**I asked this question once, and the answer completely ignored a majority of the rules listed...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Done in Java using Apache NetBeans IDE 11.2 -- Objectives: To create a data structure with...

    Done in Java using Apache NetBeans IDE 11.2 -- Objectives: To create a data structure with underlying linked chain; To utilize and implement code dealing with parity big codes for error detection; To read data from file **The other answer when searching for this question does not have a ParityChain class, a ParityChainDemo class or even include some of the stated requirements (such as hasError method). **Parity bit was specified by instructor to be LEFT most bit in chain In...

  • ****************IN C PROGRAMMING**************** Sometimes even the smallest change in data can make a big difference. Luckily,...

    ****************IN C PROGRAMMING**************** Sometimes even the smallest change in data can make a big difference. Luckily, there are algorithms that will let us not only detect when there has been an error(like checksums), but also correct when an error has occurred. These algorithms are called error-correcting codes.There are many examples of error correcting codes but one of the simplest examples is called a parity bit. A parity bit is just a single bit (1 or 0) that indicates whether a...

  • Given the data-bits m = 11010110 , determine the number of k (parity-bits) by using Hamming...

    Given the data-bits m = 11010110 , determine the number of k (parity-bits) by using Hamming Code requirements. Illustrate the error detection and correction scheme using Hamming code method, for both the sender and receiver to detect an error at the following positions: a. 6 th bit position . b. 11 th bit position . Assume an odd-parity scheme for this problem. You must show detailed calculations to receive full-credit.

  • Extra problem: Use the attached sheet to draw a 8- bit odd parity generator and a...

    Extra problem: Use the attached sheet to draw a 8- bit odd parity generator and a odd-parity checker for the 8 data bits and odd parity bit. Let the Error output be active-low (so that it goes low if there is an error and is high if there is no error) Parity Error-Detection System Using 74280s, design a complete parity generator/checking system. It is to be used in an 8-bit, even-parity computer configuration. Solution: Parity generator: Because the 74280 has...

  • Write a program in 68K assembly code that adds an odd parity to each ASCII character....

    Write a program in 68K assembly code that adds an odd parity to each ASCII character. Your code must satisfy the following specifications: 1. Define the following 64 characters in the SRC address.SRC:DC.B 'Computing and Software Systems, University of Washington Bothell' 2. Define the 64-byte space.DST:DC.B 64 3. Read each of the 64 characters, (i.e., each byte) into D0, check the number of 1s in it, set 1 to the MSB with "ORI.B #$80, D0" to create an odd parity,...

  • Can I get a circuit diagram of this and have the questions in it answered/explained? Thank...

    Can I get a circuit diagram of this and have the questions in it answered/explained? Thank you. TR. I. SINT400 quau AUC I. Parity. The parity of a string of bits is the least significant bit of their binary This sum is either 0 or 1, depending on whether the number of 1's is even or odd. This seems stupid, but adding a parity bit that makes the parity of every binary number being transmitted even allows one to determine...

  • The objective of this system is to implement an odd-bit detection system. There are three bits...

    The objective of this system is to implement an odd-bit detection system. There are three bits of inputs and one bit of output. The output is in positive logic: outputing a 1 will turn on the LED, outputing a 0 will turn off the LED. Inputs are positive logic: meaning if the switch pressed is the input is 1, if the switch is not pressed the input is 0. PE0 is an input PE1 is an input PE2 is an...

  • Instruction: For every question you answer, please show the calculation steps, if you do not show...

    Instruction: For every question you answer, please show the calculation steps, if you do not show the calculation step and show only the final result, you will not receive any score. You can use online resources for conversion, if the conversion is not a part of the question. There are a total of eight questions. Question 5: Suppose we are working with an error-correcting code that will allow all single-bit errors to be corrected for memory words of length 7....

  • In this assignment you are to utilize the Node data structure provided on Blackboard. In this...

    In this assignment you are to utilize the Node data structure provided on Blackboard. In this assignmet you are to write a main program that implements two methods and a main method as their driver. So, only main and two methods with it. Note: You may not use any of the LinkedList class provided on Blackboard, you may use the methods in it as a guide (you should actually look at them) but you cannot use any of the methods...

  • please help answer this whole question. it is all supoosed to be coded in java. i...

    please help answer this whole question. it is all supoosed to be coded in java. i will rate :) linked below is the wikipedia entry that is linked in the image below. https://en.m.wikipedia.org/wiki/Histogram QUESTION 3 10 points Save Answer Read the Wikipedia entry on what a histogram is. Write a class or collection of classes that will print a vertically-stacked histogram, using the character to build the bars. The constructor should have the range (min, max) and number of bins...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT