Question
Implement this class? Skeleton Class: BC Grader Class Please Implement these 4 operations: public static BitField add(BitField a, BitField b) { if(null == a ||
Implement this class?
Skeleton Class:
BC Grader Class
Please Implement these 4 operations:
public static BitField add(BitField a, BitField b) { if(null == a || null == b || a.size() != b.size()){ throw new IllegalArgumentException("BinaryCalculator.add(a,b): a and b cannot be null and must be the same length."); } return new BitField(a.size()); }
public static BitField subtract(BitField a, BitField b) { if(null == a || null == b || a.size() != b.size()){ throw new IllegalArgumentException("BinaryCalculator.add(a,b): a and b cannot be null and must be the same length."); } return new BitField(a.size()); }
public static BitField multiply(BitField a, BitField b) { if(null == a || null == b || a.size() != b.size()){ throw new IllegalArgumentException("BinaryCalculator.add(a,b): a and b cannot be null and must be the same length."); } return new BitField(a.size()); }
public static BitField[] divide(BitField a, BitField b) { if(null == a || null == b || a.size() != b.size()){ throw new IllegalArgumentException("BinaryCalculator.add(a,b): a and b cannot be null and must be the same length."); }
Overview In this assignment you will implementa Java class that can perform the basic arithmetic operations adid, subtract, multiply divide) on binary numbers using only logical operatore not using the actual mathematical operates that Jasa lady supports) Askeleton for the implementation is provided and can be retrieved from Canvas The zip file contains a docs/folder that has Javadoc for all the classes There are the main classes in this repository clated to this assignment: 1. BitField - this is a simple class that presents a hitfield a certain number of his long. It is basically a wrapper around a Boolean way with some convenience functions 2. HimaryCalculator - this is the section code for this assument. It has 4 methods (ad subtract, multiply, divide) that must be implemented for this assignment. You MAY NOT change the signature of these methods, they should be self-explanatory. The divide method is different from the others as i rma B a rray of 2 elements, the first of which is the quotient, the second is the remainder 3. BinaryCalculator Grader-this class generales random bit fields and then calls the four functions that must be implemented in Binary Calculator. It then determines if the returned values are correct. You can change the behavior of this class by modifying the constanta the top to focus on a single operation and/or use fewer iterations while you are working on the code For all operation, the resulting BitField objects must have the same number of bits as the input on this implies that if overfo Indrew the result that is shown will not be mathematically co -THIS IS THE EXPECTED BEHAVIOR Maximum Number of Bits Your program should be able to handle binarymbers up to 60 bits long Divide By Zero When asked to divide by your code should return from the divide method Signed versus Unsigned All of the binary values are considered to be signed with the most significant (MSB) being the sign bil, regardless of how many hits there are. Take care to understand the rules for sig of both the quotient and remainder in division package BinaryCalculator; * Class with methods to implement the basic arithmetic operations by * operating on bit fields. * This is the skeleton code for the COMP2691 Binary Calculator Assignment. public class Binary Calculator public BinaryCalculator() { super(); // TODO Auto-generated constructor stub } public static BitField add(BitField a, BitField b) if(null == a || null == b || a.size() != b.size()) { throw new IllegalArgumentException("BinaryCalculator.add(a,b): a and b cannot be null and must be the same length.") return new BitField(a.size(); public static BitField subtract(BitField a, BitField b) if(null == a || null == b || a.size() != b.size()){ throw new IllegalArgumentException("BinaryCalculator.add(a,b): a and b cannot be null and must be the same length.") return new BitField(a.size()); public static BitField multiply(BitField a, BitField b) if(null == a || null == b || a.size() != b.size()) { throw new IllegalArgumentException ("BinaryCalculator.add(a,b): a and b cannot be null and must be the same length.") return new BitField(a.size(); public static BitField[] divide (BitField a, BitField b) if(null == a || null == b || a.size() != b.size()) { throw new IllegalArgumentException("BinaryCalculator.add(a,b): a and b cannot be null and must be the same length.") // Return both the quotient and the remainder BitField() out = new BitField [ 2 ]; out[@] = new BitField(a.size()); // quotient out[1] = new BitField(a.size(); // remainder return out; 1 package BinaryCalculator; B+ import java.io.FileWriter;. in 7 public class Binary CalculatorGrader mm private static final boolean DO_ADD = true; private static final boolean DO_SUB = true; private static final boolean DO_MUL = true; private static final boolean DO_DIV = true; private static final int NUM_ITERATIONS = 100; private static final int MAX_BITS = 60; private static Random RAND = new Random(1); m in in public static void main(String[] args) throws Exception m m long n_tests = 0; long n_correct = 0; for(int i=0; iStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started