I need the interface presented in this assignment implemented and a main method driver file created to run it, I attached my previous 2 assignments that this assignment is based off of. ICSI 404 –...

1 answer below »

I need the interface presented in this assignment implemented and a main method driver file created to run it, I attached my previous 2 assignments that this assignment is based off of.


ICSI 404 – Assignment 3, the rippleAdder


This assignment builds on the previous assignment. Now that we have created a longword simulator, we can add and subtract.



Create a class called rippleAdder. You must create these two methods on this class:


public static longword add(longword a, longword b)


public static longword subtract(longword a, longword b)


The rippleAdder class should have no members and all methods on it should be static.


You may use a loop to create your ripple adder; you must use only operations on the bit class and longword class to implement your rippleAdder. You
may not
use the getSigned() or getUnsigned() methods – you must implement a rippleAdder.



You must provide a test file (rippleAdder_test.java) that implements void runTests() and call it from your main, along with your bit_test.runTests() and longword.runTests(). As with the other tests, these tests must be independent of each other and there must be reasonable coverage. You cannot reasonably test all of the billions of possible combinations, but you can test a few representative samples. Ensure that you test with positive and negative numbers.









You must submit buildable .java files for credit.



















































Rubric



Poor



OK



Good



Great



Comments



None/Excessive (0)



“What” not “Why”, few (5)



Some “what” comments or missing some (7)



Anything not obvious has reasoning (10)



Variable/Function naming



Single letters everywhere (0)



Lots of abbreviations (5)



Full words most of the time (8)



Full words, descriptive (10)



Unit Tests



None (0)



Partial Coverage


(7)



All methods covered, needs more cases (13)



All methods/cases covered (20)



Add



None (0)



Attempted (10)



Some cases work (20)



Completely working (30)



Subtract



None (0)



Attempted (10)



Some cases work (20)



Completely working (30)


Answered 1 days AfterMar 01, 2021

Answer To: I need the interface presented in this assignment implemented and a main method driver file created...

Ibrahim answered on Mar 03 2021
134 Votes
JavaRippleAdder/longword.java
JavaRippleAdder/longword.java
public class longword implements ILongword{
public bit bits[] = new bit[32];   // bit[] of size 32 is created
public longword()
{
    for(int i=0;i<32;++i) this.bits[i]=new bit();
}
public bit getBit(int i)  // Get bit i
{
    if(i>=32) throw new IllegalArgumentException("index out of bound");
    return this.bits[i];
}
public void setBit(int i, bit value) // s
et bit i's value
{
    if(value==null) throw new IllegalArgumentException("value is null");
    if(i>=32)
    {
        throw new IllegalArgumentException("index out of bounds. longword can be of size 32");
    }
    this.bits[i].set(value.getValue());
}
public longword and(longword other)  // and two longwords, returning a third
{
    if(other==null) throw new IllegalArgumentException("object is null");
    longword l = new longword();
    for(int i=0;i<32;++i)
    {
        l.setBit(i,this.bits[i].and(other.bits[i]));
    }
    return l;
}
public longword or(longword other)  // or two longwords, returning a third
{
    if(other==null) throw new IllegalArgumentException("object is null");
    longword l = new longword();
    for(int i=0;i<32;++i)
    {
        l.setBit(i,this.bits[i].or(other.bits[i]));
    }
    return l;
}
public longword xor(longword other) // xor two longwords, returning a third
{
    if(other==null) throw new IllegalArgumentException("object is null");
    longword l = new longword();
    for(int i=0;i<32;++i)
    {
        l.setBit(i,this.bits[i].xor(other.bits[i]));
    }
    return l;
}
public longword not()
{
    longword l = new longword();
    for(int i=0;i<32;++i)
    {
        l.setBit(i,this.bits[i].not());
    }
    return l;
}
public longword rightShift(int amount) // rightshift this longword by amount Bits, creating a new longword
{
    if(amount>=32 || amount<=0) throw new IllegalArgumentException("amount should be between 0 and 31");
    int i=0;
    longword l = new longword();
    if(amount==32) return l;
    for(int k=amount;k<32;++k)
    {
        l.setBit(i,this.bits[k]);
        i++;
    }
    return l;
}
public longword leftShift(int amount)// leftshift this longword by amount Bits, creating a new longword
{
    if(amount>=32 || amount<=0) throw new IllegalArgumentException("amount should be between 0 and 31");
    longword l=new longword();
    int i;
    for(i=0;i    for(int j=0;j<32-amount;++j) l.setBit(i++,this.bits[j]);
    return l;
}
public String toString()
{
    StringBuffer s = new StringBuffer();
    boolean newComma=false;
    for(int i=0;i<32;++i)
    {
        if(newComma) s.append(",");
        s.append(String.valueOf(this.bits[i].getValue()));
        newComma=true;
    }
    return s.toString();
}
public long getUnsigned() // returns the value of this longword as a long
{
    long num=0;
    for(int i=0;i<32;++i)
    {
        if(this.bits[i].getValue()==1) num+=(int)Math.pow(2,i);
    }
    return num;
}
public int getSigned() // returns the value of this longword as an int
{
    int num=0;
    for(int i=0;i<31;++i)
    {
        if(this.bits[i].getValue()==1) num+=(int)Math.pow(2,i);
    }
    if(this.bits[31].getValue()==1) return num*=-1;
    return num;
}
public void copy(longword other)
{
    if(other==null) throw new IllegalArgumentException("other object is null");
    for(int i=0;i<32;++i) this.bits[i].set(other.bits[i].getValue());
}
public void set(int value) 
{
    if(value<0) value*=-1;  // will not consider negative values in testing
    int i=value;
    int j=0;
    bit b;
    while(i>0)
    {
        b=new bit();
        b.set(i%2);
        this.setBit(j,b);
        ++j;
        i/=2;
    }
}
}
JavaRippleAdder/bit_test.java
JavaRippleAdder/bit_test.java
import java.util.*;
public class bit_test
{
    public static void runTests()
    {
        bit b1,b2;
        b1=new bit();
        b2=new bit();
        b1.set(0);
        b2.set(1);
        System.out.println("b1: "+b1);
        System.out.println("b2: "+b2);
        b1.clear();
        System.out.println(b1);
        b2.set();
        System.out.println(b2);
        System.out.println("and:"+b1.and(b2));
        System.out.println("or:"+...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here