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

[Java] Please check your code at the link I provide before you submit your code.

ID: 3832791 • Letter: #

Question

[Java] Please check your code at the link I provide before you submit your code. If your code can't pass the tester in the link, I gotta give you a down-thumb. Thank you.
Here's the link: http://www.codecheck.it/files/170402020534dq1jzkdsq9rgyi3a29vm861
Write a class, TextCondensor, whose constructor takes an ArrayList<String> as a parameter.
Provide methods:
public Set<String> condenseText() which removes any duplicates and returns an Set<String> containing words without duplicates and in alphabetical order. Think Set
public int condensedSize() which gets the number of unique elements in the text. Do this efficiently without duplicating code already written
public void setList(ArrayList<String> newText) which sets a new list of text.

Here are the files you will need:
humpty.txt:
Humpty Dumpty sat on a wall, Humpty Dumpty had a great fall. All the king's horses and all the king's men Couldn't put Humpty together again.
mary.txt:
Mary had a little lamb, little lamb, little lamb, Mary had a little lamb whose fleece was white as snow. And everywhere that Mary went Mary went, Mary went, everywhere that Mary went The lamb was sure to go.
He followed her to school one day, school one day, school one day, He followed her to school one day, Which was against the rules, It made the children laugh and play, laugh and play, laugh and play, It made the children laugh and play, To see a lamb at school.
And so the teacher turned it out, turned it out, turned it out, And so the teacher turned it out, But still it lingered near, He waited patiently about, ly about, ly about, He waited patiently about, Till Mary did appear.
"Why does the lamb love Mary so?" love Mary so?" love Mary so?" "Why does the lamb love Mary so?" The eager children cried. "Why, Mary loves the lamb, you know," lamb, you know," lamb, you know," "Why, Mary loves the lamb, you know," The teacher did reply
Use the following file:
TextCondensorRunner.java
import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; import java.util.Set;
public class TextCondensorRunner {
public static void main(String[] args) throws FileNotFoundException { TextCondensor condensor = new TextCondensor(readFile("humpty.txt")); Set<String> condensed = condensor.condenseText(); System.out.println(condensed); System.out.println(condensed.size()); condensor.setList(readFile("mary.txt")); condensed = condensor.condenseText(); System.out.println(condensed); System.out.println(condensed.size());
} public static ArrayList<String> readFile(String filename) throws FileNotFoundException { ArrayList<String> words = new ArrayList<>(); Scanner scan = new Scanner(new File(filename)); scan.useDelimiter("[^a-zA-Z']+"); while (scan.hasNext()) { words.add(scan.next().toLowerCase()); } scan.close(); return words; } }
[Java] Please check your code at the link I provide before you submit your code. If your code can't pass the tester in the link, I gotta give you a down-thumb. Thank you.
Here's the link: http://www.codecheck.it/files/170402020534dq1jzkdsq9rgyi3a29vm861
Write a class, TextCondensor, whose constructor takes an ArrayList<String> as a parameter.
Provide methods:
public Set<String> condenseText() which removes any duplicates and returns an Set<String> containing words without duplicates and in alphabetical order. Think Set
public int condensedSize() which gets the number of unique elements in the text. Do this efficiently without duplicating code already written
public void setList(ArrayList<String> newText) which sets a new list of text.

Here are the files you will need:
humpty.txt:
Humpty Dumpty sat on a wall, Humpty Dumpty had a great fall. All the king's horses and all the king's men Couldn't put Humpty together again.
mary.txt:
Mary had a little lamb, little lamb, little lamb, Mary had a little lamb whose fleece was white as snow. And everywhere that Mary went Mary went, Mary went, everywhere that Mary went The lamb was sure to go.
He followed her to school one day, school one day, school one day, He followed her to school one day, Which was against the rules, It made the children laugh and play, laugh and play, laugh and play, It made the children laugh and play, To see a lamb at school.
And so the teacher turned it out, turned it out, turned it out, And so the teacher turned it out, But still it lingered near, He waited patiently about, ly about, ly about, He waited patiently about, Till Mary did appear.
"Why does the lamb love Mary so?" love Mary so?" love Mary so?" "Why does the lamb love Mary so?" The eager children cried. "Why, Mary loves the lamb, you know," lamb, you know," lamb, you know," "Why, Mary loves the lamb, you know," The teacher did reply
Use the following file:
TextCondensorRunner.java
import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; import java.util.Set;
public class TextCondensorRunner {
public static void main(String[] args) throws FileNotFoundException { TextCondensor condensor = new TextCondensor(readFile("humpty.txt")); Set<String> condensed = condensor.condenseText(); System.out.println(condensed); System.out.println(condensed.size()); condensor.setList(readFile("mary.txt")); condensed = condensor.condenseText(); System.out.println(condensed); System.out.println(condensed.size());
} public static ArrayList<String> readFile(String filename) throws FileNotFoundException { ArrayList<String> words = new ArrayList<>(); Scanner scan = new Scanner(new File(filename)); scan.useDelimiter("[^a-zA-Z']+"); while (scan.hasNext()) { words.add(scan.next().toLowerCase()); } scan.close(); return words; } }
[Java] Please check your code at the link I provide before you submit your code. If your code can't pass the tester in the link, I gotta give you a down-thumb. Thank you.
Here's the link: http://www.codecheck.it/files/170402020534dq1jzkdsq9rgyi3a29vm861
Write a class, TextCondensor, whose constructor takes an ArrayList<String> as a parameter.
Provide methods:
public Set<String> condenseText() which removes any duplicates and returns an Set<String> containing words without duplicates and in alphabetical order. Think Set
public int condensedSize() which gets the number of unique elements in the text. Do this efficiently without duplicating code already written
public void setList(ArrayList<String> newText) which sets a new list of text.

Here are the files you will need:
humpty.txt:
Humpty Dumpty sat on a wall, Humpty Dumpty had a great fall. All the king's horses and all the king's men Couldn't put Humpty together again.
mary.txt:
Mary had a little lamb, little lamb, little lamb, Mary had a little lamb whose fleece was white as snow. And everywhere that Mary went Mary went, Mary went, everywhere that Mary went The lamb was sure to go.
He followed her to school one day, school one day, school one day, He followed her to school one day, Which was against the rules, It made the children laugh and play, laugh and play, laugh and play, It made the children laugh and play, To see a lamb at school.
And so the teacher turned it out, turned it out, turned it out, And so the teacher turned it out, But still it lingered near, He waited patiently about, ly about, ly about, He waited patiently about, Till Mary did appear.
"Why does the lamb love Mary so?" love Mary so?" love Mary so?" "Why does the lamb love Mary so?" The eager children cried. "Why, Mary loves the lamb, you know," lamb, you know," lamb, you know," "Why, Mary loves the lamb, you know," The teacher did reply
Use the following file:
TextCondensorRunner.java
import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; import java.util.Set;
public class TextCondensorRunner {
public static void main(String[] args) throws FileNotFoundException { TextCondensor condensor = new TextCondensor(readFile("humpty.txt")); Set<String> condensed = condensor.condenseText(); System.out.println(condensed); System.out.println(condensed.size()); condensor.setList(readFile("mary.txt")); condensed = condensor.condenseText(); System.out.println(condensed); System.out.println(condensed.size());
} public static ArrayList<String> readFile(String filename) throws FileNotFoundException { ArrayList<String> words = new ArrayList<>(); Scanner scan = new Scanner(new File(filename)); scan.useDelimiter("[^a-zA-Z']+"); while (scan.hasNext()) { words.add(scan.next().toLowerCase()); } scan.close(); return words; } } Use the following file:
TextCondensorRunner.java
import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; import java.util.Set;
public class TextCondensorRunner {
public static void main(String[] args) throws FileNotFoundException { TextCondensor condensor = new TextCondensor(readFile("humpty.txt")); Set<String> condensed = condensor.condenseText(); System.out.println(condensed); System.out.println(condensed.size()); condensor.setList(readFile("mary.txt")); condensed = condensor.condenseText(); System.out.println(condensed); System.out.println(condensed.size());
} public static ArrayList<String> readFile(String filename) throws FileNotFoundException { ArrayList<String> words = new ArrayList<>(); Scanner scan = new Scanner(new File(filename)); scan.useDelimiter("[^a-zA-Z']+"); while (scan.hasNext()) { words.add(scan.next().toLowerCase()); } scan.close(); return words; } }

Explanation / Answer

import java.util.ArrayList;
import java.util.Set;
import java.util.TreeSet;

/********* TextCondensor.java ***********/
// TextCondensor class
public class TextCondensor {
// To store the text/words
ArrayList<String> words;

// Constructor
TextCondensor(ArrayList<String> text) {
words = text;
}

// condenseText method - removes any duplicates and returns an Set<String>
// containing words without duplicates and in alphabetical order.
public Set<String> condenseText() {
// Set of uniqueWords to return.
// Use TreeSet since it sorts the elements alphabetically.
Set<String> uniqueWords = new TreeSet<String>();
// For each word in the words insert it to the set.
// Set will take care of duplicates.
for (String word : words) {
uniqueWords.add(word);
}

// return the uniqueWords set.
return uniqueWords;
}

// condensedSize methos - gets the number of unique elements in the text.
public int condensedSize() {
return condenseText().size();
}

// setList method - sets a new list of text.
public void setList(ArrayList<String> newText) {
words = newText;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote