Commit 60c70f61 authored by daniel.parker's avatar daniel.parker

Second.

parent e2693a15
......@@ -65,47 +65,112 @@ public class Program {
// TODO Auto-generated method stub
ConvertBinaryToInt(binaryInput);
String[] input = {"010","110","111","1010101"};
String[] input2 = {"50","110","FA","B0","F"};
System.out.println(ConvertSingb3ToInt("12"));
System.out.println(ConvertSingb20ToInt("50"));
System.out.println(ConvertSingleHexToInt("50"));
System.out.println(ConvertSingleBinaryToInt("101"));
System.out.println(Arrays.toString(ConvertBinaryToInt(input)));
}
public static int[] ConvertBinaryToInt(String[] binaryArray) {
public static int ConvertSingleBinaryToInt(String binary) {
int[] resultsArray = new int[binaryArray.length];
int wordTotal = 0;
for(int eachWord=0; eachWord<binaryArray.length;eachWord++) {
char[] characters = binaryArray[eachWord].toCharArray();
for(int i = 0; i < characters.length; i++) {
int index = (characters.length - i - 1);
double columnMultiplier = Math.pow(2, index);
if(characters[index]=='1') {
wordTotal=(int) (wordTotal + columnMultiplier);
}
int result = 0;
for (int i = 0; i < binary.length(); i++) {
int index = (binary.length() - i - 1);
double columnMultiplier = Math.pow(2, index);
if (binary.charAt(i) == '1') {
result = (int) (result + columnMultiplier);
}
resultsArray[eachWord] = wordTotal;
}
System.out.println(Arrays.toString(resultsArray));
return resultsArray;
return result;
}
public static int[] ConvertHexToInt(String[] hexArray) {
public static int[] ConvertBinaryToInt(String[] binaryArray) {
int[] resultsArray = new int[hexArray.length];
String hexidecimal = "0123456789ABCDEF";
int total = 0;
for(int eachHex = 0; eachHex < hexArray.length; eachHex++)
{
char[] hexChar = hexArray[eachHex].toCharArray();
for(int eachChar = 0; eachChar < hexChar.length; eachChar++ )
{
int[] resultsArray = new int[binaryArray.length];
for(int i = 0; i<binaryArray.length;i++) {
resultsArray[i] = resultsArray[i] + ConvertSingleBinaryToInt(binaryArray[i]);
}
return resultsArray;
}
resultsArray[eachHex] = resultsArray[eachHex] + total;
}
public static int ConvertSingleHexToInt(String hex) {
return resultsArray;
int result = 0;
for (int i = 0; i < hex.length(); i++) {
int index = (hex.length() - i - 1);
double columnMultiplier = Math.pow(16, index);
if (hex.charAt(i) == '1') {
result = (int) (result + (1*columnMultiplier));
}
if (hex.charAt(i) == '2') {
result = (int) (result + (2*columnMultiplier));
}
if (hex.charAt(i) == '3') {
result = (int) (result + (3*columnMultiplier));
}
if (hex.charAt(i) == '4') {
result = (int) (result + (4*columnMultiplier));
}
if (hex.charAt(i) == '5') {
result = (int) (result + (5*columnMultiplier));
}
if (hex.charAt(i) == '6') {
result = (int) (result + (6*columnMultiplier));
}
if (hex.charAt(i) == '7') {
result = (int) (result + (7*columnMultiplier));
}
if (hex.charAt(i) == '8') {
result = (int) (result + (8*columnMultiplier));
}
if (hex.charAt(i) == '9') {
result = (int) (result + (9*columnMultiplier));
}
if (hex.charAt(i) == '0') {
result = (int) (result + (0*columnMultiplier));
}
if (hex.charAt(i) == 'A') {
result = (int) (result + (10*columnMultiplier));
}
if (hex.charAt(i) == 'B') {
result = (int) (result + (11*columnMultiplier));
}
if (hex.charAt(i) == 'C') {
result = (int) (result + (12*columnMultiplier));
}
if (hex.charAt(i) == 'D') {
result = (int) (result + (13*columnMultiplier));
}
if (hex.charAt(i) == 'E') {
result = (int) (result + (14*columnMultiplier));
}
if (hex.charAt(i) == 'F') {
result = (int) (result + (15*columnMultiplier));
}
}
return result;
}
public static int[] ConvertHexToInt(String[] hexArray) {
int[] resultsArray = new int[hexArray.length];
for(int i = 0; i<hexArray.length;i++) {
resultsArray[i] = resultsArray[i] + ConvertSingleHexToInt(hexArray[i]);
}
return resultsArray;
}
public static int[] Union(int[] intArrayA, int[] intArrayB) {
......@@ -177,16 +242,95 @@ for(int eachHex = 0; eachHex < hexArray.length; eachHex++)
double output = 0;
for(int i = 0; i < input.length; i++) {
output = (output + input[i])/input.length;
output = output + input[i];
}
output= (output/input.length);
return output;
}
public static int ConvertSingb20ToInt(String b20) {
int result = 0;
for (int i = 0; i < b20.length(); i++) {
int index = (b20.length() - i - 1);
double columnMultiplier = Math.pow(20, index);
if (b20.charAt(i) == '1') {
result = (int) (result + (1*columnMultiplier));
}
if (b20.charAt(i) == '2') {
result = (int) (result + (2*columnMultiplier));
}
if (b20.charAt(i) == '3') {
result = (int) (result + (3*columnMultiplier));
}
if (b20.charAt(i) == '4') {
result = (int) (result + (4*columnMultiplier));
}
if (b20.charAt(i) == '5') {
result = (int) (result + (5*columnMultiplier));
}
if (b20.charAt(i) == '6') {
result = (int) (result + (6*columnMultiplier));
}
if (b20.charAt(i) == '7') {
result = (int) (result + (7*columnMultiplier));
}
if (b20.charAt(i) == '8') {
result = (int) (result + (8*columnMultiplier));
}
if (b20.charAt(i) == '9') {
result = (int) (result + (9*columnMultiplier));
}
if (b20.charAt(i) == '0') {
result = (int) (result + (0*columnMultiplier));
}
if (b20.charAt(i) == 'A') {
result = (int) (result + (10*columnMultiplier));
}
if (b20.charAt(i) == 'B') {
result = (int) (result + (11*columnMultiplier));
}
if (b20.charAt(i) == 'C') {
result = (int) (result + (12*columnMultiplier));
}
if (b20.charAt(i) == 'D') {
result = (int) (result + (13*columnMultiplier));
}
if (b20.charAt(i) == 'E') {
result = (int) (result + (14*columnMultiplier));
}
if (b20.charAt(i) == 'F') {
result = (int) (result + (15*columnMultiplier));
}
if (b20.charAt(i) == 'G') {
result = (int) (result + (16*columnMultiplier));
}
if (b20.charAt(i) == 'H') {
result = (int) (result + (17*columnMultiplier));
}
if (b20.charAt(i) == 'I') {
result = (int) (result + (18*columnMultiplier));
}
if (b20.charAt(i) == 'J') {
result = (int) (result + (19*columnMultiplier));
}
if (b20.charAt(i) == 'K') {
result = (int) (result + (20*columnMultiplier));
}
}
return result;
}
public static int[] ConvertBase20ToInt(String[] b20array) {
int[] resultsArray = new int[b20array.length];
for(int i= 0; i < b20array.length; i++) {
resultsArray[i] = resultsArray[i] + ConvertSingb20ToInt(b20array[i]);
}
return resultsArray;
......@@ -210,10 +354,31 @@ public static int Range (int[] input) {
return output;
}
public static int ConvertSingb3ToInt(String b3) {
int result = 0;
for (int i = 0; i < b3.length(); i++) {
int index = (b3.length() - i - 1);
double columnMultiplier = Math.pow(3, index);
if (b3.charAt(i) == '0') {
result = (int) (result + (0 * columnMultiplier));
}
if (b3.charAt(i) == '1') {
result = (int) (result + (1 * columnMultiplier));
}
if (b3.charAt(i) == '2') {
result = (int) (result + (2 * columnMultiplier));
}
}
return result;
}
public static int[] ConvertBase3ToInt(String[] b3array) {
int[] resultsArray = new int[b3array.length];
for(int i = 0; i<b3array.length;i++) {
resultsArray[i] = resultsArray[i] + ConvertSingb3ToInt(b3array[i]);
}
return resultsArray;
......@@ -237,36 +402,54 @@ public static int Range (int[] input) {
}
public static double StandardDeviation (int[] input) {
public static double StandardDeviation(int[] input) {
double output = 0;
//mean
for(int i = 0; i < input.length; i++) {
output = (output + input[i])/input.length;
double mean = Mean(input);
for (int i = 0; i < input.length; i++) {
double result = input[i] - mean;
result = Math.pow(result, 2);
output = output + result;
}
int result = 0;
for(int i = 0; i < input.length; i++) {
result = result + input[i];
}
output = Math.sqrt(((result-output)*(result-output)/(input.length-1)));
output = output / (input.length - 1);
output = Math.sqrt(output);
return output;
}
public static double HarmonicMean (int[] input) {
double output = 0;
for(int i = 0; i < input.length; i++) {
output = input.length/(1/(output + input[i]));
}
double inputAsDouble = input[i];
output = output + (1/inputAsDouble);
}
output = input.length/output;
return output;
}
public static double ComplexSumFunctionA (int[] input) {
double output = 0;
for(int i = 0; i < input.length; i++) {
double index = i;
double calc = 0;
calc = input[i];
calc = calc/2;
calc = Math.pow(calc, (index/2));
output = output + calc;
}
output = output / (input.length+3);
return output;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment