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

Create a class that will keep track of a single character and a count. Provide a

ID: 3561512 • Letter: C

Question

Create a class that will keep track of a single character and a count. Provide a constructor, a method to increment the count , a method to set the character, a method to reset t he count , and a toString method, which prints an empty string if the count is 0 , otherwise prints the character and the count and a linefeed. Create a driver program that will create an arr a y of these objects and set s the characters in the array to the printable characters (blank through ~). Then loops and allows the user to enter a sentence , and displays the counts, and allows the user to repeat as they wish. Use dialog box es for all I/O

Explanation / Answer

import java.util.Scanner; public class CountCharacters { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter a character for which to search: "); char ch = input.next().charAt(0); System.out.println("Enter the string to search: "); String str = input.nextLine(); int counter = 0; for (int i = 0; i
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