Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
Maths1
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
samuel.boulton
Maths1
Commits
53c7966a
Commit
53c7966a
authored
Dec 11, 2018
by
samuelboulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
final
parent
0c4946a7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
38 deletions
+22
-38
.DS_Store
.DS_Store
+0
-0
Program.java
src/Program.java
+22
-38
No files found.
.DS_Store
0 → 100644
View file @
53c7966a
File added
src/Program.java
View file @
53c7966a
...
@@ -5,7 +5,9 @@ import java.util.Random;
...
@@ -5,7 +5,9 @@ import java.util.Random;
import
java.util.Scanner
;
import
java.util.Scanner
;
public
class
Program
{
public
class
Program
{
// Name : Samuel Alexander Boulton
// ID : 169039695
public
static
String
[]
binaryInput
=
public
static
String
[]
binaryInput
=
{
{
"0010010"
,
"0010010"
,
...
@@ -71,8 +73,7 @@ public class Program {
...
@@ -71,8 +73,7 @@ public class Program {
public
static
int
[]
ConvertBinaryToInt
(
String
[]
binaryArray
)
{
public
static
int
[]
ConvertBinaryToInt
(
String
[]
binaryArray
)
{
// DONE AND PASSED TEST
int
[]
resultsArray
=
new
int
[
binaryArray
.
length
];
int
[]
resultsArray
=
new
int
[
binaryArray
.
length
];
for
(
int
i
=
0
;
i
<
binaryArray
.
length
;
i
++)
for
(
int
i
=
0
;
i
<
binaryArray
.
length
;
i
++)
...
@@ -111,7 +112,7 @@ public class Program {
...
@@ -111,7 +112,7 @@ public class Program {
}
}
public
static
int
[]
ConvertHexToInt
(
String
[]
hexArray
)
{
public
static
int
[]
ConvertHexToInt
(
String
[]
hexArray
)
{
// DONE AND PASSED TEST
int
[]
resultsArray
=
new
int
[
hexArray
.
length
];
int
[]
resultsArray
=
new
int
[
hexArray
.
length
];
for
(
int
i
=
0
;
i
<
hexArray
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
hexArray
.
length
;
i
++)
{
...
@@ -160,7 +161,7 @@ public class Program {
...
@@ -160,7 +161,7 @@ public class Program {
public
static
int
[]
Union
(
int
[]
intArrayA
,
int
[]
intArrayB
)
{
public
static
int
[]
Union
(
int
[]
intArrayA
,
int
[]
intArrayB
)
{
// DONE AND PASSED TEST
ArrayList
<
Integer
>
unionList
=
new
ArrayList
<
Integer
>();
ArrayList
<
Integer
>
unionList
=
new
ArrayList
<
Integer
>();
for
(
int
i
=
0
;
i
<
intArrayA
.
length
;
i
++)
for
(
int
i
=
0
;
i
<
intArrayA
.
length
;
i
++)
...
@@ -194,7 +195,7 @@ public class Program {
...
@@ -194,7 +195,7 @@ public class Program {
public
static
int
[]
Intersection
(
int
[]
intArrayA
,
int
[]
intArrayB
)
{
public
static
int
[]
Intersection
(
int
[]
intArrayA
,
int
[]
intArrayB
)
{
// DONE AND PASSED TEST
ArrayList
<
Integer
>
intersectList
=
new
ArrayList
<
Integer
>();
ArrayList
<
Integer
>
intersectList
=
new
ArrayList
<
Integer
>();
for
(
int
j
=
0
;
j
<
intArrayA
.
length
;
j
++)
for
(
int
j
=
0
;
j
<
intArrayA
.
length
;
j
++)
...
@@ -220,7 +221,7 @@ public class Program {
...
@@ -220,7 +221,7 @@ public class Program {
}
}
public
static
int
[]
Difference
(
int
[]
intArrayA
,
int
[]
intArrayB
)
{
public
static
int
[]
Difference
(
int
[]
intArrayA
,
int
[]
intArrayB
)
{
// DONE AND PASSED TEST
ArrayList
<
Integer
>
differenceList
=
new
ArrayList
<
Integer
>();
ArrayList
<
Integer
>
differenceList
=
new
ArrayList
<
Integer
>();
...
@@ -255,9 +256,6 @@ public class Program {
...
@@ -255,9 +256,6 @@ public class Program {
public
static
int
Sum
(
int
[]
input
)
{
public
static
int
Sum
(
int
[]
input
)
{
int
result
=
0
;
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
++)
for
(
int
i
=
0
;
i
<
input
.
length
;
i
++)
{
{
result
=
result
+
input
[
i
];
result
=
result
+
input
[
i
];
...
@@ -273,14 +271,10 @@ public class Program {
...
@@ -273,14 +271,10 @@ public class Program {
public
static
double
Mean
(
int
[]
input
)
{
public
static
double
Mean
(
int
[]
input
)
{
double
output
=
0
;
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
++)
for
(
int
i
=
0
;
i
<
input
.
length
;
i
++)
{
{
output
=
output
+
input
[
i
];
output
=
output
+
input
[
i
];
}
}
// the output result is divided by the length of the set of numbers.
return
output
/
input
.
length
;
return
output
/
input
.
length
;
}
}
...
@@ -288,7 +282,6 @@ public class Program {
...
@@ -288,7 +282,6 @@ public class Program {
public
static
int
[]
ConvertBase20ToInt
(
String
[]
b20array
)
{
public
static
int
[]
ConvertBase20ToInt
(
String
[]
b20array
)
{
// DONE AND PASSED TEST
int
[]
resultsArray
=
new
int
[
b20array
.
length
];
int
[]
resultsArray
=
new
int
[
b20array
.
length
];
for
(
int
i
=
0
;
i
<
b20array
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
b20array
.
length
;
i
++)
{
...
@@ -342,13 +335,9 @@ public class Program {
...
@@ -342,13 +335,9 @@ public class Program {
public
static
int
Range
(
int
[]
input
)
{
public
static
int
Range
(
int
[]
input
)
{
int
output
=
0
;
int
output
=
0
;
// DONE AND PASSED TEST
// Declaring the highest and lowest integers
int
highest
=
input
[
0
];
int
highest
=
input
[
0
];
int
lowest
=
input
[
0
];
int
lowest
=
input
[
0
];
// finding the highest out of the array
for
(
int
i
=
0
;
i
<
input
.
length
;
i
++)
for
(
int
i
=
0
;
i
<
input
.
length
;
i
++)
{
{
if
(
input
[
i
]
>
highest
)
if
(
input
[
i
]
>
highest
)
...
@@ -356,7 +345,7 @@ public static int Range (int[] input) {
...
@@ -356,7 +345,7 @@ public static int Range (int[] input) {
highest
=
input
[
i
];
highest
=
input
[
i
];
}
}
}
}
// finding the lowest of the array
for
(
int
j
=
0
;
j
<
input
.
length
;
j
++)
for
(
int
j
=
0
;
j
<
input
.
length
;
j
++)
{
{
if
(
input
[
j
]
<
lowest
)
if
(
input
[
j
]
<
lowest
)
...
@@ -364,7 +353,7 @@ public static int Range (int[] input) {
...
@@ -364,7 +353,7 @@ public static int Range (int[] input) {
lowest
=
input
[
j
];
lowest
=
input
[
j
];
}
}
}
}
// calculating the range
output
=
highest
-
lowest
;
output
=
highest
-
lowest
;
return
output
;
return
output
;
...
@@ -374,7 +363,7 @@ public static int Range (int[] input) {
...
@@ -374,7 +363,7 @@ public static int Range (int[] input) {
public
static
int
[]
ConvertBase3ToInt
(
String
[]
b3array
)
{
public
static
int
[]
ConvertBase3ToInt
(
String
[]
b3array
)
{
// DONE AND PASSED TEST
int
[]
resultsArray
=
new
int
[
b3array
.
length
];
int
[]
resultsArray
=
new
int
[
b3array
.
length
];
for
(
int
i
=
0
;
i
<
b3array
.
length
;
i
++)
for
(
int
i
=
0
;
i
<
b3array
.
length
;
i
++)
...
@@ -408,25 +397,21 @@ public static int Range (int[] input) {
...
@@ -408,25 +397,21 @@ public static int Range (int[] input) {
public
static
int
Mode
(
int
[]
input
)
{
public
static
int
Mode
(
int
[]
input
)
{
// DONE AND PASSED TEST
int
output
=
0
;
int
output
=
0
;
// declaring topCount integer for calculations.
int
topCount
=
0
;
int
topCount
=
0
;
// first for loop to calculate the counts of each number
for
(
int
j
=
0
;
j
<
input
.
length
;
++
j
)
for
(
int
j
=
0
;
j
<
input
.
length
;
++
j
)
{
{
int
count
=
0
;
int
count
=
0
;
// second for loop.
for
(
int
k
=
0
;
k
<
input
.
length
;
++
k
)
for
(
int
k
=
0
;
k
<
input
.
length
;
++
k
)
{
{
if
(
input
[
j
]
==
input
[
k
])
if
(
input
[
j
]
==
input
[
k
])
++
count
;
++
count
;
}
}
// if statement to calculate which number has the highest count.
if
(
count
>
topCount
)
if
(
count
>
topCount
)
{
{
// declaring the mode into output
topCount
=
count
;
topCount
=
count
;
output
=
input
[
j
];
output
=
input
[
j
];
}
}
...
@@ -440,7 +425,7 @@ public static int Range (int[] input) {
...
@@ -440,7 +425,7 @@ public static int Range (int[] input) {
public
static
double
Median
(
int
[]
input
)
{
public
static
double
Median
(
int
[]
input
)
{
// DONE AND PASSED TEST
double
output
=
0
;
double
output
=
0
;
double
sum
=
0.0
;
double
sum
=
0.0
;
Arrays
.
sort
(
input
);
Arrays
.
sort
(
input
);
...
@@ -463,7 +448,7 @@ public static int Range (int[] input) {
...
@@ -463,7 +448,7 @@ public static int Range (int[] input) {
public
static
double
StandardDeviation
(
int
[]
input
)
{
public
static
double
StandardDeviation
(
int
[]
input
)
{
// DONE AND PASSED TEST
double
output
=
0.0
;
double
output
=
0.0
;
double
length
=
0.0
;
double
length
=
0.0
;
double
totalMean
=
0.0
;
double
totalMean
=
0.0
;
...
@@ -494,7 +479,7 @@ public static int Range (int[] input) {
...
@@ -494,7 +479,7 @@ public static int Range (int[] input) {
public
static
double
HarmonicMean
(
int
[]
input
)
{
public
static
double
HarmonicMean
(
int
[]
input
)
{
//DONE AND PASSED TEST
double
output
=
0.0
;
double
output
=
0.0
;
double
sum
=
0.0
;
double
sum
=
0.0
;
for
(
int
i
=
0
;
i
<
input
.
length
;
i
++)
for
(
int
i
=
0
;
i
<
input
.
length
;
i
++)
...
@@ -511,7 +496,7 @@ public static int Range (int[] input) {
...
@@ -511,7 +496,7 @@ public static int Range (int[] input) {
public
static
double
ComplexSumFunctionA
(
int
[]
input
)
{
public
static
double
ComplexSumFunctionA
(
int
[]
input
)
{
// DONE AND PASSED TEST
double
output
=
0.0
;
double
output
=
0.0
;
double
bracketsResult
=
0.0
;
double
bracketsResult
=
0.0
;
double
powerResult
=
0.0
;
double
powerResult
=
0.0
;
...
@@ -530,7 +515,7 @@ public static int Range (int[] input) {
...
@@ -530,7 +515,7 @@ public static int Range (int[] input) {
public
static
int
[][]
MatrixScalarMultiplication
(
int
[][]
matrix
,
int
scalar
){
public
static
int
[][]
MatrixScalarMultiplication
(
int
[][]
matrix
,
int
scalar
){
// DONE AND PASSED TEST
int
[][]
resultMatrix
=
new
int
[
matrix
.
length
][
matrix
[
0
].
length
];
int
[][]
resultMatrix
=
new
int
[
matrix
.
length
][
matrix
[
0
].
length
];
for
(
int
i
=
0
;
i
<
matrix
.
length
;
i
++)
for
(
int
i
=
0
;
i
<
matrix
.
length
;
i
++)
...
@@ -553,7 +538,6 @@ public static int Range (int[] input) {
...
@@ -553,7 +538,6 @@ public static int Range (int[] input) {
public
static
int
[][]
ComplexMatrixOperation
(
int
[][]
matrix
,
int
[][]
matrix2
,
int
scalar
){
public
static
int
[][]
ComplexMatrixOperation
(
int
[][]
matrix
,
int
[][]
matrix2
,
int
scalar
){
int
[][]
resultMatrix
=
new
int
[
matrix
.
length
][
matrix
[
0
].
length
];
int
[][]
resultMatrix
=
new
int
[
matrix
.
length
][
matrix
[
0
].
length
];
// DONE AND PASSED TEST
int
[][]
sum
=
new
int
[
matrix
.
length
][
matrix
[
0
].
length
];
int
[][]
sum
=
new
int
[
matrix
.
length
][
matrix
[
0
].
length
];
for
(
int
i
=
0
;
i
<
matrix
.
length
;
i
++)
for
(
int
i
=
0
;
i
<
matrix
.
length
;
i
++)
...
@@ -572,7 +556,7 @@ public static int Range (int[] input) {
...
@@ -572,7 +556,7 @@ public static int Range (int[] input) {
public
static
double
[]
GenerateRandomDistributionForSpecificDie
(
int
iterations
)
{
public
static
double
[]
GenerateRandomDistributionForSpecificDie
(
int
iterations
)
{
// DONE AND PASSED TEST
double
[]
resultsArray
=
new
double
[
5121
];
double
[]
resultsArray
=
new
double
[
5121
];
Random
rng
=
new
Random
(
1234
);
Random
rng
=
new
Random
(
1234
);
...
@@ -615,7 +599,7 @@ public static int Range (int[] input) {
...
@@ -615,7 +599,7 @@ public static int Range (int[] input) {
public
static
double
[]
GenerateRandomDistribution
(
int
dieSides
,
int
rolls
,
int
iterations
)
{
public
static
double
[]
GenerateRandomDistribution
(
int
dieSides
,
int
rolls
,
int
iterations
)
{
// DONE AND PASSED TEST
double
[]
resultsArray
=
new
double
[(
dieSides
*
rolls
)+
1
];
double
[]
resultsArray
=
new
double
[(
dieSides
*
rolls
)+
1
];
Random
rng
=
new
Random
(
1234
);
Random
rng
=
new
Random
(
1234
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment