Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

**Java Language only** Directions:the code below tells me the first second and third numbers which are most relevant in the array as well as the

**Java Language only**

Directions:the code below tells me the first second and third numbers which are most relevant in the array as well as the how many times they popped up in the code, using the data below Add to the code making it tell me what the numbers chance percentage of it being in the rang of (1-5)(6-10)(11-15)(16-20)(21-25)(26-30)(31-35)(36-40)(41-45)(46-50) (51-55)(56-60)(61-65)(66-70) Only 1 throught 70. Example below..

I will Thumbs up good work thanks!!

/**

Example :

Array: {12,10, 4, 28, 56, 3, 70,63,22,48}

Output: chances 1-5= 20%

chances 6-10=10%

chances 11-15=10%

chances 16-20=0%

chances 21-25=10%

chances 26-30=10%

chances . 31-35=0%

chances 36-40=0%

chances 41-45=0%

chances 46-50=10%

chances 51-55=0%

chances 56-60=10%

chances 61-65=10%

chances 66-70=10%

*/

//Cheggs.java

import java.util.Comparator;

import java.util.HashMap;

import java.util.Map;

import java.util.TreeMap;

public class Cheggs {

public static TreeMap getFrequencyMap(int num[]) {

HashMap counts = new HashMap();

for (int i = 0; i < num.length; i++) {

if (counts.containsKey(num[i])) {

int c = counts.get(num[i]) + 1;

counts.put(num[i], c);

}

else {

counts.put(num[i], 1);

}

}

ValueComparator bvc = new ValueComparator(

counts);

TreeMap sortedMap = new TreeMap(bvc);

sortedMap.putAll(counts);

return sortedMap;

}

public static void main(String args[]) {

int num1[] = { 3, 6, 14, 1, 31, 1, 2, 9, 32, 1, 1, 1, 50, 21, 1, 2, 13,

2, 17, 2, 11, +1, 1, 14, 22, 5, 2, 11, 16, 3, 21, 14, 8, 4, 2,

7, 3, 1, 12, 8, 7, 16, 4, 11, 7, 4, 14, 5, 6, 7, 1, +24, 10, 7,

17, 14, 5, 28, 14, 1, 29, 10, 2, 3, 2, 8, 13, 28, 4, 4, 10, 1,

28, 2, 8, 6, 14, 76, 10, 56, 3, +3, 5, 6, 1, 10, 6, 17, 20, 6,

51, 2, 7, 21, 12, 25, 1, 5, 8, 15, 26, 4, 11, 4, 2 };

int num2[] = { 20, 6, 16, 31, 26, 03, 2, 9, 65, 1, 1, 1, 40, 21, 1, 2,

13, 2, 17, 2, 11, +1, 1, 14, 22, 5, 2, 11, 16, 9, 21, 14, 8, 4,

2, 2, 3, 1, 12, 8, 5, 16, 4, 11, 7, 4, 14, 1, 6, 7, 1, +24, 10,

7, 17, 14, 5, 28, 14, 1, 29, 10, 2, 3, 3, 17, 16, 28, 1, 4, 10,

1, 28, 4, 8, 6, 14, 16, 10, 16, 3, +3, 1, 6, 1, 10, 6, 17, 20,

6, 31, 2, 7, 21, 12, 25, 1, 5, 9, 18, 26, 4, 11, 4, 2, };

int num3[] = { 60, 60, 15, 5, 5, 5, 5, 60, 8, 8,40,50,60,10,20,30,40,50,60+ 4,6,50,45,32,67,26,42,35,67,69,34,37,38,5,67,45,23,12,47};

int num4[] = { 24, 4, 90, 4, 25, 25, 4, 25, 4,40,10,45,67,56,34,34,58,30,34,54+ 7,4,2,6,8,30,35,70,50,30,29,10,43,65,43,23,43,25,75,23,67,43,21,64,23,};

int num5[] = { 53, 57, 59, 60, 60, 60, 60, 12, 12,6,4,2,6,16,27,23,25,28,50,30+ 45,70,20,34,56,78,12,34,56,70,23,45,67,50,64,35,64,};

int num6[] = { 20, 20, 5, 3, 8, 8, 8, 8, 5, 5,8,9,6,34,23,25,26,12,16,70,45,67+ 8,6,45,65,34,23,47,43,45,47,48,49,50,30,24,12,54,62,45,56};

TreeMap sortedMap1 = getFrequencyMap(num1);

TreeMap sortedMap2 = getFrequencyMap(num2);

TreeMap sortedMap3 = getFrequencyMap(num3);

TreeMap sortedMap4 = getFrequencyMap(num4);

TreeMap sortedMap5 = getFrequencyMap(num5);

TreeMap sortedMap6 = getFrequencyMap(num6);

for (int i = 0; i < 3; i++) {

if (i == 0) {

System.out.print("First Relevance Number: output:");

/**

* storing all the keys (relevant numbers) in integer variables

*/

int v1 = (Integer) sortedMap1.keySet().toArray()[i];

int v2 = (Integer) sortedMap2.keySet().toArray()[i];

int v3 = (Integer) sortedMap3.keySet().toArray()[i];

int v4 = (Integer) sortedMap4.keySet().toArray()[i];

int v5 = (Integer) sortedMap5.keySet().toArray()[i];

int v6 = (Integer) sortedMap6.keySet().toArray()[i];

// displaying them

System.out.print(v1 + "," + v2 + "," + v3 + "," + v4 + "," + v5

+ "," + v6);

System.out.println();

System.out.print(" Most relevant numbers came up ");

/**

* displaying relevant numbers and their number of occurrences

*/

System.out.print("(" + v1 + " came up " + sortedMap1.get(v1)

+ " times) ");

System.out.print("(" + v2 + " came up " + sortedMap2.get(v2)

+ " times) ");

System.out.print("(" + v3 + " came up " + sortedMap3.get(v3)

+ " times) ");

System.out.print("(" + v4 + " came up " + sortedMap4.get(v4)

+ " times) ");

System.out.print("(" + v5 + " came up " + sortedMap5.get(v5)

+ " times) ");

System.out.print("(" + v6 + " came up " + sortedMap6.get(v6)

+ " times) ");

System.out.println();

}

if (i == 1) {

System.out.print(" Second Relevance Number: output:");

int v1 = (Integer) sortedMap1.keySet().toArray()[i];

int v2 = (Integer) sortedMap2.keySet().toArray()[i];

int v3 = (Integer) sortedMap3.keySet().toArray()[i];

int v4 = (Integer) sortedMap4.keySet().toArray()[i];

int v5 = (Integer) sortedMap5.keySet().toArray()[i];

int v6 = (Integer) sortedMap6.keySet().toArray()[i];

System.out.print(v1 + "," + v2 + "," + v3 + "," + v4 + "," + v5

+ "," + v6);

System.out.println();

System.out.print(" Second most relevant numbers came up ");

System.out.print("(" + v1 + " came up " + sortedMap1.get(v1)

+ " times) ");

System.out.print("(" + v2 + " came up " + sortedMap2.get(v2)

+ " times) ");

System.out.print("(" + v3 + " came up " + sortedMap3.get(v3)

+ " times) ");

System.out.print("(" + v4 + " came up " + sortedMap4.get(v4)

+ " times) ");

System.out.print("(" + v5 + " came up " + sortedMap5.get(v5)

+ " times) ");

System.out.print("(" + v6 + " came up " + sortedMap6.get(v6)

+ " times) ");

System.out.println();

}

if (i == 2) {

System.out.print(" Third Relevance Number: output:");

int v1 = (Integer) sortedMap1.keySet().toArray()[i];

int v2 = (Integer) sortedMap2.keySet().toArray()[i];

int v3 = (Integer) sortedMap3.keySet().toArray()[i];

int v4 = (Integer) sortedMap4.keySet().toArray()[i];

int v5 = (Integer) sortedMap5.keySet().toArray()[i];

int v6 = (Integer) sortedMap6.keySet().toArray()[i];

System.out.print(v1 + "," + v2 + "," + v3 + "," + v4 + "," + v5

+ "," + v6);

System.out.println();

System.out.print(" Third most relevant numbers came up ");

System.out.print("(" + v1 + " came up " + sortedMap1.get(v1)

+ " times) ");

System.out.print("(" + v2 + " came up " + sortedMap2.get(v2)

+ " times) ");

System.out.print("(" + v3 + " came up " + sortedMap3.get(v3)

+ " times) ");

System.out.print("(" + v4 + " came up " + sortedMap4.get(v4)

+ " times) ");

System.out.print("(" + v5 + " came up " + sortedMap5.get(v5)

+ " times) ");

System.out.print("(" + v6 + " came up " + sortedMap6.get(v6)

+ " times) ");

System.out.println();

}

}

}

}

class ValueComparator> implements Comparator {

Map base;

public ValueComparator(Map base) {

this.base = base;

}

@Override

public int compare(T1 k1, T1 k2) {

T2 val1 = base.get(k1);

T2 val2 = base.get(k2);

return val2.compareTo(val1);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago