Commit 53c7966a authored by samuelboulton's avatar samuelboulton

final

parent 0c4946a7
File added
......@@ -5,7 +5,9 @@ import java.util.Random;
import java.util.Scanner;
public class Program {
// Name : Samuel Alexander Boulton
// ID : 169039695
public static String[] binaryInput =
{
"0010010",
......@@ -71,8 +73,7 @@ public class Program {
public static int[] ConvertBinaryToInt(String[] binaryArray) {
// DONE AND PASSED TEST
int[] resultsArray = new int[binaryArray.length];
for(int i = 0; i<binaryArray.length; i++)
......@@ -111,7 +112,7 @@ public class Program {
}
public static int[] ConvertHexToInt(String[] hexArray) {
// DONE AND PASSED TEST
int[] resultsArray = new int[hexArray.length];
for(int i = 0; i<hexArray.length; i++) {
......@@ -160,7 +161,7 @@ public class Program {
public static int[] Union(int[] intArrayA, int[] intArrayB) {
// DONE AND PASSED TEST
ArrayList<Integer> unionList = new ArrayList<Integer>();
for(int i = 0; i < intArrayA.length; i++)
......@@ -194,7 +195,7 @@ public class Program {
public static int[] Intersection(int[] intArrayA, int[] intArrayB) {
// DONE AND PASSED TEST
ArrayList<Integer> intersectList = new ArrayList<Integer>();
for(int j = 0; j < intArrayA.length; j++)
......@@ -220,7 +221,7 @@ public class Program {
}
public static int[] Difference(int[] intArrayA, int[] intArrayB) {
// DONE AND PASSED TEST
ArrayList<Integer> differenceList = new ArrayList<Integer>();
......@@ -255,9 +256,6 @@ public class Program {
public static int Sum (int[] input) {
int result = 0;
// DONE AND PASSED TEST
// the for loop goes through each number and does the calculation each time.
for(int i = 0; i < input.length; i++)
{
result = result + input[i];
......@@ -273,14 +271,10 @@ public class Program {
public static double Mean (int[] input) {
double output = 0;
// DONE AND PASSED TEST
// for loop that goes through each number and calculates the output each time.
for(int i = 0; i < input.length; i++)
{
output = output + input[i];
}
// the output result is divided by the length of the set of numbers.
return output / input.length;
}
......@@ -288,7 +282,6 @@ public class Program {
public static int[] ConvertBase20ToInt(String[] b20array) {
// DONE AND PASSED TEST
int[] resultsArray = new int[b20array.length];
for(int i = 0; i<b20array.length; i++) {
......@@ -342,13 +335,9 @@ public class Program {
public static int Range (int[] input) {
int output = 0;
// DONE AND PASSED TEST
// Declaring the highest and lowest integers
int highest = input[0];
int lowest = input[0];
// finding the highest out of the array
for(int i = 0; i < input.length; i++)
{
if(input[i] > highest)
......@@ -356,7 +345,7 @@ public static int Range (int[] input) {
highest = input[i];
}
}
// finding the lowest of the array
for(int j = 0; j < input.length; j++)
{
if(input[j] < lowest)
......@@ -364,7 +353,7 @@ public static int Range (int[] input) {
lowest = input[j];
}
}
// calculating the range
output = highest - lowest;
return output;
......@@ -374,7 +363,7 @@ public static int Range (int[] input) {
public static int[] ConvertBase3ToInt(String[] b3array) {
// DONE AND PASSED TEST
int[] resultsArray = new int[b3array.length];
for(int i = 0; i<b3array.length; i++)
......@@ -408,25 +397,21 @@ public static int Range (int[] input) {
public static int Mode (int[] input) {
// DONE AND PASSED TEST
int output = 0;
// declaring topCount integer for calculations.
int topCount = 0;
// first for loop to calculate the counts of each number
for (int j = 0; j < input.length; ++j)
{
int count = 0;
// second for loop.
for (int k = 0; k < input.length; ++k)
{
if (input[j] == input[k])
++count;
}
// if statement to calculate which number has the highest count.
if (count > topCount)
{
// declaring the mode into output
topCount = count;
output = input[j];
}
......@@ -440,7 +425,7 @@ public static int Range (int[] input) {
public static double Median (int[] input) {
// DONE AND PASSED TEST
double output = 0;
double sum = 0.0;
Arrays.sort(input);
......@@ -463,7 +448,7 @@ public static int Range (int[] input) {
public static double StandardDeviation (int[] input) {
// DONE AND PASSED TEST
double output = 0.0;
double length = 0.0;
double totalMean = 0.0;
......@@ -494,7 +479,7 @@ public static int Range (int[] input) {
public static double HarmonicMean (int[] input) {
//DONE AND PASSED TEST
double output = 0.0;
double sum = 0.0;
for(int i = 0; i<input.length; i++)
......@@ -511,7 +496,7 @@ public static int Range (int[] input) {
public static double ComplexSumFunctionA (int[] input) {
// DONE AND PASSED TEST
double output = 0.0;
double bracketsResult = 0.0;
double powerResult = 0.0;
......@@ -530,7 +515,7 @@ public static int Range (int[] input) {
public static int[][] MatrixScalarMultiplication (int[][] matrix, int scalar){
// DONE AND PASSED TEST
int[][] resultMatrix = new int[matrix.length][matrix[0].length];
for(int i = 0; i < matrix.length; i ++)
......@@ -553,7 +538,6 @@ public static int Range (int[] input) {
public static int[][] ComplexMatrixOperation(int[][] matrix,int[][] matrix2, int scalar){
int[][] resultMatrix = new int[matrix.length][matrix[0].length];
// DONE AND PASSED TEST
int[][] sum = new int[matrix.length][matrix[0].length];
for(int i = 0; i<matrix.length; i++)
......@@ -572,7 +556,7 @@ public static int Range (int[] input) {
public static double[] GenerateRandomDistributionForSpecificDie(int iterations) {
// DONE AND PASSED TEST
double[] resultsArray = new double[5121];
Random rng = new Random(1234);
......@@ -615,7 +599,7 @@ public static int Range (int[] input) {
public static double[] GenerateRandomDistribution(int dieSides, int rolls, int iterations) {
// DONE AND PASSED TEST
double[] resultsArray = new double[(dieSides*rolls)+1];
Random rng = new Random(1234);
......
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