/home/caleb/ASDV-Java/Semester 2/Assignments/lab3_CalebFontenot/src/main/java/com/calebfontenot/lab3_calebfontenot/MyInteger.java |
nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt
nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java
package com.calebfontenot.lab3_calebfontenot;
@author
public class MyInteger {
private int value;
@return
public int getValue()
{
return this.value;
}
@Override
public int hashCode()
{
int hash = 7;
return hash;
}
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final MyInteger other = (MyInteger) obj;
return this.value == other.value;
}
@Override
public String toString()
{
return "MyInteger{" + "value=" + value + '}';
}
public MyInteger(int value)
{
this.value = value;
}
public static boolean isEven(MyInteger other) {
return other.getValue() % 2 == 0;
}
public static boolean isPrime(MyInteger other) {
int numToTest = other.getValue();
for (int i = 2; i <= numToTest / 2; ++i) {
if (numToTest % i == 0) {
return false;
}
}
return true;
}
public static int parseInteger(char[] array) {
String s = "";
for (char i: array) {
s += i;
}
return Integer.parseInt(String.valueOf(s));
}
public static void main(String[] args)
{
System.out.println(parseInteger(new char[] {'7', '6'}));
System.out.println(MyInteger.isPrime(new MyInteger(3)));
System.out.println(MyInteger.isEven(new MyInteger(4)));
System.out.println(MyInteger.isEven(new MyInteger(3)));
}
}