Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

HOME INSERTDESIGNPAGE LAYOUT REFERENCESMAILINGS REVIEW VIEW Copy Format Painter

ID: 3594344 • Letter: H

Question

HOME INSERTDESIGNPAGE LAYOUT REFERENCESMAILINGS REVIEW VIEW Copy Format Painter oard No Spac. Headin Font Paragraph 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 r changes the value of tag by calling the private method changeTag. e 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 points

Explanation / Answer

Android.java:

import java.math.BigInteger;

public class Android {

private static int tag = 1;

private String name;

public Android(String name) {

this.name = "Bob" + tag;

changeTag();

}

public String getName() {

return name;

}

private static boolean isPrime() {

// below utility checks if the value of bigInteger is a prime

BigInteger b = new BigInteger(String.valueOf(tag));

return b.isProbablePrime(1);

}

private static void changeTag() {

// below utility gives the next big integer which is prime

BigInteger b = new BigInteger(String.valueOf(tag));

tag = Integer.parseInt(b.nextProbablePrime().toString());

}

}