complete TODO's using java:
-Main-
package edu.luc.cs271.wordcount;
import java.util.*;
public class Main {
public static void main(final String[] args) throws InterruptedException {
// set up the scanner so that it separates words based on space and punctuation
final Scanner input = new Scanner(System.in).useDelimiter("[^\\p{Alnum}]+");
// TODO complete this main program
// 0. create suitable map instance
// 1. create a WordCounter instance
// 2. use this to count the words in the input
// 3. determine the size of the resulting map
// 4. create an ArrayList of that size and
// 5. store the map's entries in it (these are of type Map.Entry<String, Integer>)
// 6. sort the ArrayList in descending order by count
// using Collections.sort and an instance of the provided comparator (after fixing the latter)
// 7. print the (up to) ten most frequent words in the text
}
}
-DescendingByCount-
package edu.luc.cs271.wordcount;
import java.util.Comparator;
import java.util.Map;
/** The comparison strategy for sorting the array by the word count. */
public class DescendingByCount implements Comparator<Map.Entry<String, Integer>> {
public int compare(final Map.Entry<String, Integer> l, final Map.Entry<String, Integer> r) {
// TODO turn this into descending order using the getValue() method on l and r
return -1;
}
}
-WordCounter-
Step by stepSolved in 3 steps with 2 images
- I have the following code: import java.util.*; import java.io.*; public class GradeBook { publicstaticvoidmain(String[] args)throwsIOException{ // TODO Auto-generated method stub File infile =newFile("students.dat"); Scanner in =newScanner(infile); while(in.hasNext()){ // Read information form file and create a student object and print String name = in.nextLine(); Student student =newStudent(name, in.nextLine()); for(int i =1; i <=4;++i){ student.setQuiz(i, in.nextInt()); } student.setMidtrmExm(in.nextInt()); student.setFinalExm(in.nextInt()); in.nextLine(); // Calculate grade and letter grade; double overallQuizScore=0.0,score=0.0; for(int i=1;i<=student.NUM_QUIZZES;i++) { overallQuizScore+=(student.getQuiz(i)/student.QUIZ_MAX_POINTS)*100; } overallQuizScore = (overallQuizScore/4)*0.30; score =…arrow_forwardimport java.util.Scanner; public class StateInfo { /* Your code goes here */ public static void main(String[] args) { Scanner scnr = new Scanner(System.in); String stateCode; String stateName; stateCode = scnr.next(); stateName = scnr.next(); printStateInfo(stateCode, stateName); }}arrow_forwardimport java.util.Scanner; public class AverageWithSentinel{ public static final int END_OF_INPUT = -500; public static void main(String[] args) { Scanner in = new Scanner(System.in); // Step 2: Declare an int variable with an initial value // as the count of input integers // Step 3: Declare a double variable with an initial value // as the total of all input integers // Step 4: Display an input prompt // "Enter an integer, -500 to stop: " // Step 5: Read an integer and store it in an int variable // Step 6: Use a while loop to update count and total as long as // the input value is not -500. // Then display the same prompt and read the next integer // Step 7: If count is zero // Display the following message // "No integers were…arrow_forward
- import java.util.Arrays; import java.util.Random; public class Board { /** * Construct a puzzle board by beginning with a solved board and then * making a number of random moves. That some of the possible moves * don't actually change what the board looks like. * * @param moves the number of moves to make when generating the board. */ public Board(int moves) { throw new RuntimeException("Not implemented"); } The board is 5 X 5. You can add classes and imports like rand.arrow_forwardimport java.util.Scanner; public class ParkingFinder {/* Your code goes here */ public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int numVisits; int duration; numVisits = scnr.nextInt(); duration = scnr.nextInt(); System.out.println(findParkingPrice(numVisits, duration)); }}arrow_forwardimport java.util.Scanner; public class DebugSix4 { public static void main(String[] args) { int high, low, count = 0; final int NUM = 5; Scanner input = new Scanner(System.in); System.out.print("This application displays " + NUM + " random numbers" + "\nbetween the low and high values you enter" + "\nEnter low value now... "); low = input.nextInt(); // Inserted the missing semicolon System.out.print("Enter high value... "); high = input.nextInt(); // Added the missing dot to the method call. while (low >= high) { // For proper input validation, changed "" to ">=" System.out.println("The number you entered for a high number, " + high + ", is not more than " + low); System.out.print("Enter a number higher than " + low + "... "); high =…arrow_forward
- I need help with this code !! import java.util.Arrays;import java.util.Scanner; public class MaxElement {public static void main(String[] args) { //create an object for Scanner class Scanner x = new Scanner (System.in);System.out.print ("Enter 10 integers: ");// create an arrayInteger[] arr = new Integer[10]; // Execute for loopfor (int i = 0; i < arr.length; i++) {//get the 10 integersarr[i] = x.nextInt(); } // Print the maximum numberSystem.out.print("The max number is = " + max(arr));System.out.print("\n"); } //max method public static <E extends Comparable<E>> E max(E[] arr) {E max = arr[0]; // Execute for loop for (int i = 1; i < arr.length; i++) { E element = arr[i];if (element.compareTo(max) > 0) {max = element;}}return max; }}arrow_forwardimport java.util.Scanner; public class RomanNumerals { public static void main(String[] args) { Scanner in = new Scanner("I C X D M L"); char romanNumeral = in.next().charAt(0); System.out.println("Value: " + valueOf(romanNumeral) + " Expected: 1") ; romanNumeral = in.next().charAt(0); System.out.println("Value: " + valueOf(romanNumeral) + " Expected: 100") ; romanNumeral = in.next().charAt(0); System.out.println("Value: " + valueOf(romanNumeral) + " Expected: 10") ; romanNumeral = in.next().charAt(0); System.out.println("Value: " + valueOf(romanNumeral) + " Expected: 500") ; romanNumeral = in.next().charAt(0); System.out.println("Value: " + valueOf(romanNumeral) + " Expected: 1000") ; romanNumeral = in.next().charAt(0); System.out.println("Value: " + valueOf(romanNumeral) + " Expected: 50") ; } /** Gives the value…arrow_forwardimport java.util.Scanner; public class CircleAndSphereWhileLoop{ public static final double MAX_RADIUS = 500.0; public static void main(String[] args) { Scanner in = new Scanner(System.in); // Step 2: Read a double value as radius using prompt // "Enter the radius (between 0.0 and 500.0, exclusive): " // Step 3: While the input radius is not in the ragne (0.0, 500.0) // Display a message on one line (ssuming input value -1) // "The input number -1.00 is out of range." // Read a double value as radius using the same promt double circumference = 2 * Math.PI * radius; double area = Math.PI * radius * radius; double surfaceArea = 4 * Math.PI * Math.pow(radius, 2); double volume = (4 / 3.0) * Math.PI * Math.pow(radius, 3); // Step 4: Display the radius, circle circumference, circle area, // sphere surface area, and…arrow_forward
- Using Java.arrow_forwardStringFun.java import java.util.Scanner; // Needed for the Scanner class 2 3 /** Add a class comment and @tags 4 5 */ 6 7 public class StringFun { /** * @param args not used 8 9 10 11 12 public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Please enter your first name: "); 13 14 15 16 17 18 System.out.print("Please enter your last name: "); 19 20 21 //Output the welcome message with name 22 23 24 //Output the length of the name 25 26 27 //Output the username 28 29 30 //Output the initials 31 32 33 //Find and output the first name with switched characters 34 //All Done! } } 35 36 37arrow_forwardHow do I code: public static void rotateElements(int[] arr, int rotationCount) public static void reverseArray(int[] arr) In Java?arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY