Alpha Geek

(8)

$10/per page/Negotiable

About Alpha Geek

Levels Tought:
University

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Environmental science,Essay writing,Programming,Social Science,Statistics Hide all
Teaching Since: Apr 2017
Last Sign in: 438 Weeks Ago, 3 Days Ago
Questions Answered: 9562
Tutorials Posted: 9559

Education

  • bachelor in business administration
    Polytechnic State University Sanluis
    Jan-2006 - Nov-2010

  • CPA
    Polytechnic State University
    Jan-2012 - Nov-2016

Experience

  • Professor
    Harvard Square Academy (HS2)
    Mar-2012 - Present

Category > Computer Science Posted 23 Apr 2017 My Price 15.00

Design a class named MyInteger

Design a class named MyInteger. The class contains:
A????1 An int instance variable named value that stores the int value represented by the object.
A????1 A constructor that creates a MyInteger object for the specified int value.
A????1 A get method that returns the int value.
A????1 Static methods isEven(int), isOdd(int) and isPrime(int) that return true if the specified value is odd, even, or
prime, respectively, and false otherwise.
A????1 Methods isEven(), isOdd(), and isPrime() that return true if the value in this object is even, odd or prime,
respectively, and false otherwise.
A????1 Static methods isEven(MyInteger), isOdd(MyInteger) and isPrime(MyInteger) that return true if the value of
the specified object is even, odd, or prime, respectively, and false otherwise.
A????1 Method equals(int) that returns true if the value in this object is equal to the specified integer.
A????1 Method equals(MyInteger) that return true if the value in this object is equal to the value in another object.
A????1 Static method parseInt(char[]) that converts an array of numeric characters to an int value.
A????1 Static method parseInt(String) that converts a string into an int value.
Note: if c is a character from A????10A????1 to A????19A????1, then (int)c-48 converts c to an integer value.
You may assume that the user enters only digits.
HereA????1s a demo class that tests the above methods and the output. Use a similar demo class.
public class MyIntegerDemo
{
public static void main(String[] args)
{
MyInteger n1 = new MyInteger(5);
System.out.println("n1 is " + n1.getValue());
System.out.println("n1 is even? " + n1.isEven());
System.out.println("n1 is odd? " + n1.isOdd());
System.out.println("n1 is prime? " + n1.isPrime());
System.out.println("15 is prime? " + MyInteger.isPrime(15));
char[] chars = {'3','5','3','9'};
System.out.println(MyInteger.parseInt(chars));
String s = "9786";
System.out.println(MyInteger.parseInt(s));
MyInteger n2 = new MyInteger(24);
System.out.println("n2 is " + n2.getValue());
System.out.println("n2 is odd? " + n2.isOdd());
System.out.println("45 is odd? " + MyInteger.isOdd(45));
System.out.println("n1 is equal to n2? " + n1.equals(n2));
System.out.println("n1 is equal to 5? " + n1.equals(5));
}
}
----jGRASP exec: java -ea MyIntegerDemo
n1 is 5
n1 is even? false
n1 is odd? true
n1 is prime? true
15 is prime? false
3539
9786
2 is 24
n2 is odd? false
45 is odd? true
n1 is equal to n2? false
n1 is equal to 5? true
----jGRASP: operation complete

Answers

(8)
Status NEW Posted 23 Apr 2017 10:04 AM My Price 15.00

-----------

Attachments

file 1492944058-Answer.docx preview (543 words )
S-----------olu-----------tio-----------n: ----------- pu-----------bli-----------c c-----------las-----------s M-----------yIn-----------teg-----------er -----------{ -----------  -----------  -----------//c-----------las-----------s v-----------ari-----------abl-----------esÂ-----------  Â-----------  i-----------nt -----------val-----------ue;----------- Â-----------  Â-----------  /-----------/co-----------nst-----------ruc-----------tor-----------  -----------  -----------pub-----------lic----------- My-----------Int-----------ege-----------r(i-----------nt -----------val-----------ue)----------- {Â-----------  Â-----------  Â-----------  Â-----------  t-----------his-----------.va-----------lue----------- = -----------val-----------ue;-----------  -----------  -----------} -----------  -----------  -----------//g-----------ett-----------er -----------set-----------ter-----------  -----------  -----------pub-----------lic----------- in-----------t g-----------etV-----------alu-----------e()----------- {Â-----------  Â-----------  Â-----------  Â-----------  r-----------etu-----------rn -----------val-----------ue;-----------  -----------  -----------} -----------  -----------  -----------pub-----------lic----------- vo-----------id -----------set-----------Val-----------ue(-----------int----------- va-----------lue-----------) {-----------  -----------  -----------  -----------  -----------thi-----------s.v-----------alu-----------e =----------- va-----------lue-----------; -----------  ----------- } -----------  -----------  ----------- //----------- ch-----------eck----------- ev-----------en -----------num-----------ber-----------  -----------  -----------pub-----------lic----------- bo-----------ole-----------an -----------isE-----------ven-----------() -----------{ -----------  -----------  -----------  ----------- if----------- (t-----------his-----------.va-----------lue----------- % -----------2 =-----------= 0-----------) {----------- 
Not Rated(0)