Xyg: Mail-fazle rabbiivel, xC Chegg Study |Guided S https://outlook office.com/o
ID: 3596703 • Letter: X
Question
Xyg: Mail-fazle rabbiivel, xC Chegg Study |Guided S https://outlook office.com/owa ?realm=lvelagcccuny.edu&exsvurl;=1&l; My LaGuardia. Student × OfficeHome c Microsoft Corporation IUS] Office 365 Outlook Download 4 Edit and reply Word Online Accessibility Mode-, Pnnt Fnd Extra Credits P. 475 5 points 11. Create a class Android whose objects have unique data. The class has the following attributes: tag-a static integer that begins at 1 and changes each time an instance is created name-a string that is unique for each instance of this class Android has the following methods .Android-a default constructor that sets the name to Bob" concatenated with the value of tag. After setting the name, this constructor changes the value of tag by calling the private method changeTag getName-returns the name portion of the invoking object .isPrime (n)-a private static method that returns true if n is prime-that is, if it is not divisible by any number from 2 to n-1 . changeTag--a private static method that replaces tag with the next prime number larger than the current value of tag p-480 10 pointsExplanation / Answer
Given below is the code for the question. Please don't forget to rate the answer if it helped. Thank you.
To indent code in eclipse, select code using Ctrl+A and then press Ctrl+i
public class Android {
private static int tag = 1;
private String name;
//default constructor
public Android()
{
name = "Bob" + tag;
changeTag(); //call changeTag to change the value of tag
}
public String getName()
{
return name;
}
private static boolean isPrime(int n)
{
for(int i = 2; i < n; i++) //check with numbers from 2 to n-1
{
if(n % i == 0) //is n divisble by i
return false;
}
return true;
}
private static void changeTag()
{
do
{
tag++;
}while(!isPrime(tag)); //till tag becomes next prime number
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.