Question: 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
1- an integer private member P that is prime at all times.
2- getter
3- 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
4- A default constructor that sets P to the first prime: 2
5- A constructor that accepts an integer and sets P to that value if prime otherwise the next prime
6- toString
7- equals
8- add method that accepts an integer and return a prime that's the sum of the integer and P
9- overload add method to accept a Prime object abd return Prime object the sum of the two.
10- 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 isPrime(int a){
if(a ==2)
return true;
if(a <2|| a%2==0)
return false;
for (int i =3; i <= Math.sqrt(a); i+=2){
if(a%i ==0){
return false;
}
}
return true;
}
*/
public class Prime {
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!