Answered step by step
Verified Expert Solution
Link Copied!

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
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

Step: 1

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

Fundamentals Of Database System

Authors: Elmasri Ramez And Navathe Shamkant

7th Edition

978-9332582705

More Books

Students also viewed these Databases questions

Question

1. How does Kiwi Experience maintain a continual customer focus?

Answered: 1 week ago