Answered step by step
Verified Expert Solution
Question
1 Approved Answer
package Prime; / * Design and code a class that has the following properties 1 - an integer private member P that is prime at
package Prime;
Design and code a class that has the following properties
an integer private member P that is prime at all times.
getter
setter that accepts an integer and sets p to it if prime, otherwise it sets P to the next prime number greater than the value
A default constructor that sets P to the first prime:
A constructor that accepts an integer and sets P to that value if prime otherwise the next prime
toString
equals
add method that accepts an integer and return a prime that's the sum of the integer and P
overload add method to accept a Prime object abd return Prime object the sum of the two.
A tester class to test all methods and constructors.
Here is the code to check if a number is prime, make this method private to your class
boolean isPrimeint a
ifa
return true;
ifa a
return false;
for int i ; i Math.sqrta; i
ifai
return false;
return true;
public class Prime
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