Computers and Technology
Computers and Technology, 03.07.2020 17:01, dondre54

Here is the question: (The MyInteger class ) Design a class named MyInteger. The class contains:
* An int data field named value that stores the int value represented by this object .
* A constructor that creates a MyInteger object for the specified int value . A getter method that returns the int value .
* The methods isEven(), isOdd(), and isPrime() that return true if the value in this object is even, odd, or prime, respectively.
* The static methods isEven(int ), isOdd(int ), and isPrime(int ) that return true if the specified value is even, odd, or prime, respectively.
* The static methods isEven(MyInteger), isOdd(MyInteger), and isPrime(MyInteger) that return true if the specified value is even, odd, or prime, respectively.
* The methods equals (int ) and equals (MyInteger) that return true if the value in this object is equal to the specified value .
* A static method parseInt(char []) that converts an array of numeric characters to an int value .
* A static method parseInt(String ) that converts a string into an int value .
Draw the UML diagram for the class and then implement the class . Write a client program that tests all methods in the class . Given that the definition of a prime number is a positive integer be sure to instruct the use to only enter positive integers .
SAMPLE RUN #2
Need Help with this part...
--- Prompts For Keyboard/Console/Standard Input ---
Enter a positive integer to create a MyInteger object or to move on to next part of program :
Enter a positive integer to test static isXXX(int ) methods or to move on to next part of program :
Enter a positive integer to test static isXXX(MyInteger) methods or to move on to next part of program :
Enter a the first of two positive integers to create obj2 and test obj2.equals (int ) or to move on to next part of program :
Enter a the second of two positive integers to test obj2.equals (int ):
Enter a the first of two positive integers to create obj2 and test obj2.equals (MyInteger obj3) or to move on to next part of program :
Enter a the second of two positive integers to create obj3 and test obj2.equals (MyInteger obj3):
Enter a positive integer that will be placed into a char [] array to demonstrate the MyInteger. parseInt(char []):
Enter a positive integer that will be placed into a String to demonstrate the MyInteger. parseInt(String ):
Inputs
--- Keyboard/Console/Standard Input stdin ---
1
4
6
9
12
11
108
109
111
89
46
47
48
49
37
37
112
122
112
112
189222
333
107
22897
203
207
201
7
So Far I have the following code but need to test it:
import java. util.*;
public class MyInteger {
// store value
private int value;
//constructor for MyInteger
public MyInteger(int value){
this. value = value;
}
// Getter method to return in value
public int getValue(){
return value;
}
//Method for even
public boolean isEven(){
return(value%2 == 0);
}
// Method for odd
public boolean isOdd(){
return(value%2!=0);
}
// Method for prime
public boolean isPrime(){
if (value == 2)return true;
for (int i = 2; i*i<=value; i++){
if(value%i==0) return false;
}
return true;
}
// static method isEven
public static boolean isEven(int val){
return(val%2 == 0);
}
//static method isOdd
public static boolean isOdd (int val){
return(val%2!=0);
}
//static method isPrime
public static boolean isPrime(int val){
if(val==2)return true;
for(int i=2; i*i if(val%i==0)return false;
}
return true;
}
// static method return for is even
public static boolean isEven(MyInteger M){
return M. isEven();
}
// static method return for is odd
public static boolean isOdd(MyInteger M){
return M. isOdd();
}
// static method return for is prime
public static boolean isPrime(MyInteger M){
return M. isPrime();
}
//true if value in object = specified value
public boolean equals(int val){
return value == val;
}
public boolean equals(MyInteger M){
return value==M. value;
}
//static method parseInt convert array char to int value
public static int parselInt(char[] val){
int num = 0;
for(int i=0; i num = 10*num + (int)(val[i]-'0');
return num;
}
//static method parseInt String
public static int parseInt(String val){
int num = 0;
for(int i=0; i num = 10*num + (int)(val. charAt(i)-'0');
return num;
}
// test program
public static void main(String[] args){
Scanner input = new Scanner(System. in);
need suggestion on how to do the second part of the code..

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 00:40, 1fuzzybirdow6e0s
If you arrive at the same time as another user straight across from you yield if a. they flash your headlights at you b. you can’t see their turn signals c. you’re going street and they’re running d. you’re turning they’re going straight plz
Answers: 1
image
Computers and Technology, 22.06.2019 06:30, gracie2492
What result from the passage of this amendment
Answers: 1
image
Computers and Technology, 23.06.2019 09:30, rowdycar313p0ao5k
[java] create an application called registrar that has the following classes: a. a student class that minimally stores the following data fields for a student: - name - student id number - number of credits - total grade points earned and this class should also be provides the following methods: - a constructor that initializes the name and id fields - a method that returns the student name field - a method that returns the student id field - methods to set and retrieve the total number of credits - methods to set and retrieve the total number of grade points earned. - a method that returns the gpa (grade points divided by credits) b. an instructor class that minimally stores the following data fields for an instructor: - name - faculty id number - department the following methods should be provided: - a constructor that initializes the name and id fields - methods to set and retrieve the instructor’s department. c. a course class that minimally stores the following data for a course: - name of the course- course registration code- maximum number of 35 students- instructor- number of students- students registered in the course (an array)the following methods should also be provided: - a constructor that initializes the name, registration code, and maximum number of students- methods to set and retrieve the instructor- a method to search for a student in the course; the search should be based on an id number.- a method to add a student to the course. if the course is hill, then an exception with an appropriate message should be raised (try creating your own exception class for this). also, be sure that the student is not already registered in the course. the list of students should be in the order that they registered.- a method to remove a student from the course. if the student is not found, then an exception with an appropriate message should be raised (use the same exception class mentioned a method that will allow course objects to be output to a file using object serialization- a method that will allow course objects to be read in from a file created with object serializationyou will note that the student and instructor classes described above have some commonality. create aperson class that captures this commonality and uses it as a base class for student and instructor. this class should be responsible for the name and id fields and also provide atostring method that returns a string of the form name, id. this will be the inheritedtostring method for the student and instructor classes.1. draw a uml diagram for diss application.2. implement the previous classes in java. write a main program that can serve as a test class that tests all of the methods created and demonstrates that they are working
Answers: 2
image
Computers and Technology, 23.06.2019 17:00, evanwall91
What does the faves button do? a. users mark a web page as a favorite b. leads other readers to favor a specific page c. readers sort and align their favicons, or favorite icons d. leads users to a message board where they can post questions
Answers: 1
Do you know the correct answer?
Here is the question: (The MyInteger class ) Design a class named MyInteger. The class contains:

Questions in other subjects:

Konu
English, 16.12.2019 05:31
Konu
Mathematics, 16.12.2019 05:31