Answered step by step
Verified Expert Solution
Question
1 Approved Answer
LongInteger Class Implement a class named LongInteger. The class contains: A private data field of type long A constructor that takes parameter of type long
LongInteger Class
Implement a class named LongInteger. The class contains:
A private data field of type long
A constructor that takes parameter of type long and creates LongInteger object for the specified long value.
toLong method that returns the value of the field.
The instance methods isEven isOdd and isPrime that return true if the value in the object is even, odd, or prime respectively.
The static methods isEvenlong isOddlong and isPrimelong that return true if the specified value is even, odd, or prime respectively.
The instance method equalslong and instance method equalsLongInteger that return true if the value in this object is equal to the specified value.
A static method parseLongString that converts a string into an long value, positive or negative. Method throws IllegalArgumentException when
A string contains nondigit characters other than as the very first character of the sting
A string has only and no digits.
A string represents a number that is too large to be stored as long and produces overflow
A string represents a number that is too small to be stored as long and produces underflow
Test cases:
import java.ioPrintWriter;
public class TestLongInteger
public static boolean testsPrintWriter outputStream
outputStream.printlnr
LongInteger Class TEST SETS r
;
boolean t testLongIntegerClassoutputStream;
boolean t testLongIntegerClassoutputStream;
boolean t testLongIntegerClassoutputStream;
return t&&t&&t;
public static boolean testLongIntegerClassPrintWriter outputStream
int count ;
int expectedCount ;
int a ;
int b ;
int prime ;
Test #
LongInteger num new LongIntegera;
ifnumtoLonga
outputStream.printfss
"LongInteger TEST SET : constructor", "PASSED";
count;
else outputStream.printfss
"LongInteger TEST SET : constructor", "FAILED";
Test #
LongInteger num new LongIntegerb;
ifnumisEven&& numisOdd&& numisEven && numisOdd
outputStream.printfss
"LongInteger TEST SET : isEven and isOdd "PASSED";
count;
else outputStream.printfss
"LongInteger TEST SET : isEven and isOdd "FAILED";
Test #
LongInteger num new LongIntegerprime;
ifnumisPrime && numisPrime && numisPrime
outputStream.printfss
"LongInteger TEST SET : isPrime "PASSED";
count;
else outputStream.printfss
"LongInteger TEST SET : isPrime "FAILED";
if countexpectedCount return true;
else return false;
public static boolean testLongIntegerClassPrintWriter outputStream
int count ;
int expectedCount ;
int a ;
int b ;
int prime ;
Test #
ifLongInteger.isEvena&& LongInteger.isOdda&& LongInteger.isEvenb && LongInteger.isOddb
outputStream.printfss
"LongInteger TEST SET : static isEven and static isOdd "PASSED";
count;
else outputStream.printfss
"LongInteger TEST SET : static isEven and static isOdd "FAILED";
Test #
ifLongIntegerisPrimeprime && LongInteger.isPrimea && LongInteger.isPrimeb
outputStream.printfss
"LongInteger TEST SET : static isPrime "PASSED";
count;
else outputStream.printfss
"LongInteger TEST SET : static isPrime "FAILED";
Test #
LongInteger num new LongIntegera;
LongInteger num new LongIntegera;
LongInteger num new LongIntegerb;
ifnumequalsa && numequalsb && numequalsnum && numequalsnum
outputStream.printfss
"LongInteger TEST SET : both equals methods", "PASSED";
count;
else outputStream.printfss
"LongInteger TEST SET : both equals methods", "FAILED";
if countexpectedCount return true;
else return false;
public static boolean testLongIntegerClassPrintWriter outputStream
int count ;
int expectedCount ;
Test #
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