Once your UML diagram is complete implement the class naming the Java file MyInteger.java. Create another Java file, a program named MyIntegerTester.java that tests all methods in the class. One technique is to write both classes at the same time. As much as possible you implement and test one method at a time. This minimized the amount of new code you have to look at when debugging a method. Only the Version 4.0 “tester” file will have main() method in it. Here is a sample run of what the output of MyIntegerTester might look like. Tests use MyInteger n1 object constructed with MyIneger(5) Testing equals(int), n1 and 6: false Testing equals(MyInteger), n1 and n2 = 7: false Testing isEven(), n1 which is 5, is even? false Testing isOdd(), n1 which is 5, is odd? true Testing static isPrime(), n1 which is 5, is prime? true Testing instance isPrime(), 5 is prime? true Next two tests use char[] and Sring data of 3539 Testing parseInt(char[]): 3539 Testing parseInt(String)Passing: 3539
class MyInteger {
private int value;
public MyInteger(int aValue) {
super();
value = aValue;
}
public boolean isEven() {
return value % 2 == 0;
}
public boolean isOdd() {
return value % 2 == 1;
}
public boolean isPrime() {
if (value == 2)
return
true;
if (value % 2 == 0)
return
false;
for (int i = 2; i < value;
i++)
if (value % i ==
0)
return false;
return true;
}
public boolean isEven(int value) {
return value % 2 == 0;
}
public boolean isOdd(int value) {
return value % 2 == 1;
}
public boolean isPrime(int value) {
if (value == 2)
return
true;
if (value % 2 == 0)
return
false;
for (int i = 2; i < value;
i++)
if (value % i ==
0)
return false;
return true;
}
public boolean isEven(MyInteger value) {
return value.isEven();
}
public boolean isOdd(MyInteger value) {
return value.isOdd();
}
public boolean isPrime(MyInteger value) {
return value.isPrime();
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result +
value;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return
true;
if (obj == null)
return
false;
if (getClass() !=
obj.getClass())
return
false;
MyInteger other = (MyInteger)
obj;
if (value != other.value)
return
false;
return true;
}
public int parseInt(String s) {
return Integer.parseInt(s);
}
public int parseInt(char s[]) {
return Integer.parseInt(new
String(s));
}
}
public class MyIntegerTester {
public static void main(String[] args) {
MyInteger n1 = new
MyInteger(5);
System.out.println(n1.equals(6));
MyInteger n2 = new
MyInteger(7);
System.out.println(n1.equals(n2));
System.out.println(n1.isEven());
System.out.println(n1.isOdd());
System.out.println(n1.isPrime());
System.out.println(n1.parseInt("3539"));
System.out.println(n1.parseInt("3539".toCharArray()));
}
}
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me
Once your UML diagram is complete implement the class naming the Java file MyInteger.java. Create another...
. 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(), is Odd(), 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...
Java: Create the skeleton. Create a new file called ‘BasicJava4.java’ Create a class in the file with the appropriate name. public class BasicJava4 { Add four methods to the class that return a default value. public static boolean isAlphabetic(char aChar) public static int round(double num) public static boolean useSameChars(String str1, String str2) public static int reverse(int num) Implement the methods. public static boolean isAlphabetic(char aChar): Returns true if the argument is an alphabetic character, return false otherwise. Do NOT use...
Draw the UML DIAGRAM ALSO PLEASE DRAW THE UML DIAGRAM.ALSO in java should use the program in java For this task you will create a Point3D class to represent a point that has coordinates in three dimensions labeled x, y and z. You will then use the class to perform some calculations on an array of these points. You need to draw a UML diagram for the class (Point3D) and then implement the class The Point3D class will have the...
in java please Purpose: To practice designing a class that can be used in many applications. To write and implement a thorough test plan. You are NOT to use any of the Java API date classes (Gregorian calendar, Date…) except for the constructor method to set the date fields to the current data. Write a class to hold data and perform operations on dates. Ie: January 2, 2019 or 3/15/2018 You must include a toString( ), an equals( ) and...
need source code for NetBeans here is the file Write a class PrimeSequence that implements the Sequence interface of Worked Example 10.1* and produces a sequence of prime numbers. * See Files section bj6_ch10_we.pdf Hint: Pseudocode to produce next prime: class Prime Sequence implements Sequence instance variable int p function next ()I isPrime-true While (isPrime) increment p; for (d-2; until d*d > p divides p) isPrime-false; d+) if (d if isPrime) return p; isPrime-true Use your PrimeSequence class to generate...
Create a UML diagram to help design the class described in exercise 3 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Baby class object; should they be private or public? Determine what class methods are required; should they be private or public? Write Java code for a Baby class. A Baby has a name of type String and an age of type integer. Supply two constructors:...
*****************************In Java***************************************In Java***********************************In Java************************* In this problem, you will implement various algorithms operating on binary search trees. We have provided with you a standard implementation of a generic BST in BinarySearchTree.java. Note that this class is an abstract class, which means that some of its methods are not implemented. In previous assignments, you have implemented interfaces which specified methods that you needed to write. Very similarly, an abstract class is a class with some unimplemented methods (it can be thought...
Please use java code. Implement a test class named BatArray1Test that tests all the functionality of the following given 3 methods, including the invalid arguments: 1) commonEnd Given two arrays of ints, a and b, return true if they have the same first element or they have the same last element. This method should return false if either array is empty or null. 2) midThree Given an array of integers, return a new array of length 3 containing the elements...
using CSCI300 java Given the following UML Class Diagram Club_Card # card_num : String # name : String # age: int # year: int + Club_Card (all parameters) + Setters & Getters + toString() : String + equals(x: Object): boolean [10 pts] Define the class Club_Card, which contains: 1. All arguments constructor which accepts all required arguments from the main and instantiate a Club_Card object. 2. Set & get method for each data attribute. 3. A toString() method which returns...
Create a UML diagram to help design the class described in exercise 3 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Baby class object; should they be private or public? Determine what class methods are required; should they be private or public? 3. Write Java code for a Baby class. A Baby has a name of type String and an age of type integer. Supply two...