Progress on diagonal searching

This commit is contained in:
2025-10-19 21:30:59 -05:00
parent 1d0dc8215f
commit a8bae2d408
6 changed files with 520 additions and 12 deletions

View File

@@ -5,6 +5,7 @@
package com.calebfontenot.lab3_calebfontenot;
import java.util.Date;
import java.util.Objects;
/**
*
@@ -100,5 +101,46 @@ public class Account {
System.out.println(account1);
System.out.println(account2);
System.out.println(account1.equals(account2));
System.out.println(account1.equals(new A()));
}
}
public void withdraw(double amount) {
this.balance -= amount;
}
// public void withdraw(double amount) {
// this.balance -= amount;
// }
@Override
public int hashCode()
{
int hash = 3;
return hash;
}
@Override
public boolean equals(Object obj)
{
// If the parameter obj is the same as this object
if (this == obj) { // compare addresses
return true;
}
if (obj == null) { // parameter is null
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
// here we are certain
final Account other = (Account) obj;
if (this.id != other.id) {
return false;
}
if (Double.doubleToLongBits(this.balance) != Double.doubleToLongBits(other.balance)) {
return false;
}
return Objects.equals(this.dateCreated, other.dateCreated);
}
}class A {}

View File

@@ -0,0 +1,85 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.calebfontenot.lab3_calebfontenot;
/**
*
* @author caleb
*/
public class MyInteger {
private int value;
/**
* Get the value of value
*
* @return the value of value
*/
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)));
}
}