Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA JAVA JAVA Please include output in answer so I can give you credit!!!! And

ID: 3688979 • Letter: J

Question

JAVA JAVA JAVA
Please include output in answer so I can give you credit!!!! And answer in less than 3 hours :s

Objective:

Write a program that heap sorts an arbitrary number of words or sentences from the least number of F’s (ignoring case) in the word to the most number of F’s in the word. Write a frontend in that will take in each word or phrase, and then sort and prints them.

Example Dialog:

Welcome to the F word sorter! Enter words or phrases and it will sort from least number of F’s to the most number of F’s. Enter “Sort” to finish and sort.

FUN

Fluffy

Fife

Five Dollar Foot Long For Five Dollars

FfffFFffuuu!

Farmer Fred Fiddles for Food

After Friday fear the final. Be afraid friend.

Sort

The sorted phrases are

FUN

Fife

Fluffy

Five Dollar Foot Long For Five Dollars

Farmer Fred Fiddles for Food

After Friday fear the final. Be afraid friend.

FfffFFffuuu!

Explanation / Answer

This is almost completed program. Only pending this to sort the Sortarray based on the F's count:

import java.util.Scanner;
import java.util.*;
import java.lang.*;


public class HelloWorld{

public static void main(String []args){
System.out.println("Hello World");
  
Scanner reader = new Scanner(System.in); // Reading from System.in
System.out.println("Welcome to the F word sorter!");
System.out.println("Enter words or phrases and it will sort from least number of Fs to the most number of Fs.");
System.out.println("Enter Sort to finish and sort.");

String s;
String end = "Sort";

ArrayList<String> mylist = new ArrayList<String>();
ArrayList<String> sortlist = new ArrayList<String>();
// to hold all the temporary count of F's
ArrayList<Integer> templist = new ArrayList<Integer>();

// while loop to get all the input strings till the user enters "Sort"
while (reader.hasNextLine())
{
s = reader.next();
if(s.equals(end))
break;
else
mylist.add(s);
}

// display the array list
System.out.println("Contents of list: " + mylist);

// CODE to count F's and fill integer list with counter values
for(String counter: mylist){
          
           int count = 0;
           for( int i=0; i<counter.length(); i++ ) {
               if( (counter.charAt(i) == 'F') || (counter.charAt(i) == 'f') ) {
                   count++;
               }
           }
      
   templist.add(count);

          
}
// display the integer array list
System.out.println("Contents of list: " + templist);

// to arrange the elements in the String arraylist by finding the min's of Interger arraylist
int min = templist.get(0);

for(Integer i: templist) {
if(i < min)
// min = templist.indexOf(templist);
}
System.out.println("minimum position is: " + min);

// minor tweek is required here to store the index of mylist(min) in sortlist

sortlist.add(mylist.get(min-1));
// display the integer array list
// System.out.println("Contents of Sortedlist: " + sortlist);


}
}