Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Update MyByte class only to run MyByte 2 Tester.java ( method stubs marked / / TODO ) : package MyByte 2 Starter; public class MyByte
Update MyByte class only to run MyByteTester.java method stubs marked TODO:
package MyByteStarter;
public class MyByte
public static final int MAXVAL ; unsigned positive only
public static final int MINVAL ; unsigned positive only
public static final int MAXSIGNEDVAL ;
public static final int MINSIGNEDVAL ;
public static final MyByte MAXBIN new MyByte;
public static final MyByte MINBIN new MyByte;
public static final int NUMBITS ;
private boolean isSigned false;
private boolean val;
public MyByteString byteString
this.val new booleanNUMBITS;
if byteStringlength NUMBITS
throw new IllegalArgumentExceptionInvalid binary string length";
for int i ; i NUMBITS; i
this.vali byteString.charAti;
public MyByteint value
this.val new booleanNUMBITS;
if value MAXVAL
throw new IllegalArgumentExceptionValue is too large to store in a byte";
else if value MINVAL
if value MINSIGNEDVAL
throw new IllegalArgumentExceptionValue is too negative to store in a byte";
this.isSigned true;
For negative values, use two's complement representation
value MAXVAL value ;
Convert the integer to binary representation
for int i NUMBITS ; i ; i
this.valivalue & ;
value ;
public void setBitint index, boolean val
this.valindex val;
public boolean getBitint index
return this.valindex;
public String toString
String binaryText ;
forint i ; i; i
if vali binaryText ;
else binaryText ;
if i binaryText ; add a space to write bits grouped
return binaryText;
public MyByte addString value
MyByte operand new MyBytevalue;
return addoperand;
public MyByte addint value
MyByte operand new MyBytevalue;
return addoperand;
public MyByte addMyByte value
TODO Autogenerated method stub
return null;
public int getSignedVal
TODO Autogenerated method stub
return ;
public int getUnsignedVal
TODO Autogenerated method stub
return ;
public MyByte andMyByte op
MyByte result new MyByte;
for int i ; i NUMBITS; i
result.setBiti getBiti && opgetBiti;
return result;
public MyByte orMyByte op
MyByte result new MyByte;
for int i ; i NUMBITS; i
result.setBiti getBiti opgetBiti;
return result;
public MyByte xorMyByte op
MyByte result new MyByte;
for int i ; i NUMBITS; i
result.setBiti getBiti opgetBiti;
return result;
package MyByteStarter;
public class MyByteTester
public static void mainString args
int score ;
score testConstants;
score testConstructors;
score testSigned;
score testAddInt;
score testAddMyByte;
score testAddString;
score testAND;
score testOR;
score testXOR;
System.out.printlncurrent score: score intscore;
System.out.printlnEnd of program.";
private static int testXOR
int points ;
MyByte op new MyByte;
MyByte op new MyByte;
MyByte xorByte opxorop;
if xorByte.equals new MyByte
points ;
else
System.out.printlnFailed OR test: XOR
tYou had optoString XOR optoString xorByte.toString;
return points;
private static int testOR
int points ;
MyByte op new MyByte;
MyByte op new MyByte;
MyByte orByte oporop;
if orByte.equals new MyByte
points ;
else
System.out.printlnFailed OR test: OR
tYou had optoString OR optoString orByte.toString;
return points;
Chegg does not allow me to post the rest of the MyByteTester class
Step 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