Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program Specification: Being able to program with numbers that do not (in theory) havea maximum value is a necessity in many applications of computerscience. You

Program Specification:

Being able to program with numbers that do not (in theory) havea maximum value is a necessity in many applications of computerscience. You are going to write a series of classes to get startedon this task. Your final class will allow you to represent and atleast add Binary numbers of arbitrary length.

public abstract AbstractBit

You are to write (implement) this class exactly as dictated bythe following list of class members -

private boolean bit;

public abstract AbstractBit clone();

public abstract AbstractBit addBits(AbstractBit guest);

public abstract AbstractBit addBits(AbstractBit guest1,AbstractBit guest2);

public abstract AbstractBit carryBit(AbstractBit guest);

public abstract AbstractBit carryBit(AbstractBit guest1,AbstractBit guest2);

protected void setBit(boolean value)

public boolean getBit()

public AbstractBit()

public AbstractBit(boolean value)

public AbstractBit(AbstractBit guest)

public boolean equals(AbstractBit guest)

public String toString() ?

public BinaryBit extends AbstractBit

You are to write (implement) this class exactly as dictated bythe following list of class members -

public static final BinaryBit zero = new BinaryBit(false);

public static final BinaryBit one = new BinaryBit(true);

public BinaryBit()

public BinaryBit(boolean bit)

public BinaryBit(int bit) public BinaryBit(BinaryBit guest)

public BinaryBit clone()

public boolean equals(BinaryBit guest)

public String toString()

public AbstractBit addBits(AbstractBit guest)

public AbstractBit addBits(AbstractBit guest1, AbstractBitguest2)

public AbstractBit carryBit(AbstractBit guest)

public AbstractBit carryBit(AbstractBit guest1, AbstractBitguest2)

public BitString

You are to write (implement) this class exactly as dictated bythe following list of class members -

private ArrayList bitString;

private void setAbstractBitList(ArrayList bitList)

protected ArrayList getAbstractBitList()

public void addBit(AbstractBit bit)

public AbstractBit bitAt(int loc)

public BitString()

protected BitString(ArrayList bitList)

public BitString(BitString guest)

public boolean isEmpty()

public int length()

public BitString clone()

public boolean equals(BitString guest)

public String toString()

public Binary extends BitString

You are to write (implement) this class exactly as dictated bythe following list of class members -

public Binary()

public Binary(long val)

public Binary(BitString guest)

public Binary(Binary guest)

public Binary clone()

private void encode(long val)

public Binary addition(Binary guest)

Your Class must also work with the following DriverClass

// public Driver:

public class Driver {

public static void main(String[] args) {

Binary n1 = new Binary();

Binary n2 = new Binary(10);

Binary n3 = n2.clone();

System.out.println("n1 = " + n1);

System.out.println("n1.length() = " + n1.length());

System.out.println("n2 = " + n2);

System.out.println("n2.length() = " + n2.length());

System.out.println("n3 = " + n3);

System.out.println("n3.length() = " + n3.length());

System.out.println("n3.bitAt(1) = " + n3.bitAt(1));

System.out.println();

System.out.println("n1 equals n1 ? " + n1.equals(n1));

System.out.println("n1 equals n2 ? " + n1.equals(n2));

System.out.println("n2 equals n3 ? " + n2.equals(n3));

System.out.println();

Binary n4 = n2.addition(n2);

System.out.println("n4 = " + n4);

for (int i = 0; i <= 10; ++i) {

n4 = n4.addition(n4);

n4 = n4.addition(n2);

System.out.println("n4 = " + n4);

}

}

}

And produce the following output exactly:

n1 = 0

n1.length() = 1

n2 = 1010

n2.length() = 4

n3 = 1010

n3.length() = 4

n3.bitAt(1) = 1

n1 equals n1 ? true

n1 equals n2 ? false

n2 equals n3 ? true

n4 = 10100

n4 = 110010

n4 = 1101110

n4 = 11100110

n4 = 111010110

n4 = 1110110110

n4 = 11101110110

n4 = 111011110110

n4 = 1110111110110

n4 = 11101111110110

n4 = 111011111110110

n4 = 1110111111110110

Step by Step Solution

3.38 Rating (157 Votes )

There are 3 Steps involved in it

Step: 1

Editable code Driverjava import javaio public class Main public static void mainString args Binary n1 new Binary Binary n2 new Binary10 Binary n3 n2cl... 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

Data Analysis And Decision Making

Authors: Christian Albright, Wayne Winston, Christopher Zappe

4th Edition

538476125, 978-0538476126

More Books

Students also viewed these Programming questions

Question

What are the advantages and disadvantages of Groupon?

Answered: 1 week ago

Question

Describe the process of observational learning.

Answered: 1 week ago