Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is a java class bit which we need to convert to a bit collection(using array) and then turn that into an integer inside the

Here is a java class bit which we need to convert to a bit collection(using array) and then turn that into an integer inside the word class

public class bit { private int value; // constructor to initialize the bit value to 0 public bit() { value = 0; }

// method to set the bit's value to passed value @Override public void set(int value) { if(value >= 0 && value <= 1) // validate input value is 0 or 1 this.value = value; else // invalid value, throw exception throw new IllegalArgumentException("ERROR: Bit can be set to 0 or 1"); }

// method to toggle the value from 0 to 1 or 1 to 0 @Override public void toggle() { if(value == 0) value = 1; else value = 0; }

// method to set value to 1 @Override public void set() { value = 1; }

// method to set value to 0 @Override public void clear() { value = 0; }

// method to return bit's value @Override public int getValue() { return value; }

// method to perform and on two bits and return a new bit set to the result @Override public bit and(bit other) { bit result = new bit(); // create a new bit for the result if(value == 0) // if any one of the value is 0, set result to 0 result.clear(); else { if(other.getValue() == 0) result.clear(); else // if both values are 1 , set result to 1 result.set(); } return result; }

// method to perform or on two bits and return a new bit set to the result @Override public bit or(bit other) { bit result = new bit(); // create a new bit for the result if(value == 1) // if any one of the value is 1, set the result to 1 result.set(); else { if(other.getValue() == 1) result.set(); else // both values are 0, set result to 0 result.clear(); } return result; }

// method to perform xor on two bits and return a new bit set to the result @Override public bit xor(bit other) { bit result = new bit(); // create a new bit for the result if(value == 1) // if one of the bit's value is 1, set result to 1, else set it to 0 { if(other.getValue() == 0) result.set(); else result.clear(); }else { if(other.getValue() == 1) result.set(); else result.clear(); } return result; }

// method to perform not on the existing bit, returning the result as a new bit @Override public bit not() { if(value == 0) set(); else clear(); return this; } // method to return String representation of the bit public String toString() { return value+""; } }

Follow the steps inside the word class

public class word{

//Create must create a collection (array is best) of Bit (from class bit) and use that for storage

//Turn the collection into an integer using Math.Pow()

//Implement on the following methods

bit getBit(int i){} // Get bit i

void setBit(int i, bit value){} // set bit i's value

}

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

Recommended Textbook for

Databases And Information Systems 1 International Baltic Conference Dbandis 2020 Tallinn Estonia June 19 2020 Proceedings

Authors: Tarmo Robal ,Hele-Mai Haav ,Jaan Penjam ,Raimundas Matulevicius

1st Edition

303057671X, 978-3030576714

More Books

Students also viewed these Databases questions

Question

define EFFECTIVE PARTICIPATION

Answered: 1 week ago