Explanation of Solution
Creating “CharacterFrequency.java”:
- Import required package.
- Define “CharacterFrequency” class.
- Define main function.
- Create array for digit count using “ArrayList”.
- Initialize the digit counts.
- Create object for scanner class.
- Prompt statement for telephone number.
- Read the telephone number from user.
- Compute the count of each character in the telephone number using “for” loop.
- Define each character in telephone number.
- Performs “switch” case.
- If the digit character is “0”, then increment the count of character “0” using “set” and “get” method
- If the digit character is “1”, then increment the count of character “1”.
- If the digit character is “2”, then increment the count of character “2”.
- If the digit character is “3”, then increment the count of character “3”.
- If the digit character is “4”, then increment the count of character “4”.
- If the digit character is “5”, then increment the count of character “5”.
- If the digit character is “6”, then increment the count of character “6”.
- If the digit character is “7”, then increment the count of character “7”.
- If the digit character is “8”, then increment the count of character “8”.
- If the digit character is “9”, then increment the count of character “9”.
- Prompt statement for count of each digit.
- Display the count of each digit using “for” loop.
- Display the count by using “get” method.
- Display count of each digit.
- Define main function.
Program:
The below java program is used to compute the count of each digit in a telephone number using “ArrayList”.
“CharacterFrequency.java”
//Import required package
import java.util.*;
//Define "CharacterFrequency" class
public class CharacterFrequency
{
//Define main function
public static void main(String[] args)
{
/* Create array for digit count using "ArrayList" */
ArrayList<Integer> digit_count = new ArrayList<Integer>();
//Initialize the digit counts
for(int i = 0; i < 10; i++)
{
digit_count.add(0);
}
//Create object for scanner class
Scanner reader = new Scanner(System.in);
//Prompt statement for user
System.out.print("Enter a telephone number: ");
//Read the telephone number from user
String telephoneNumber = reader.next();
/* Compute the count of each character in the telephone number */
for(int i = 0; i < telephoneNumber.length(); i++)
{
/* Define each character in telephone number */
Character digit = telephoneNumber.charAt(i);
//Performs "switch" case
switch(digit)
{
/* If the digit character is "0", then */
case '0':
/* Increment the count of character '0' by using "set" and "get" method */
digit_count.set(0, digit_count.get(0)+1);
break;
/* If the digit character is "1", then */
case '1':
/* Increment the count of character '1' */
digit_count...
Want to see the full answer?
Check out a sample textbook solutionChapter 12 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
- I have a few questions I need help with Statement: When we build a nearest neighbor model, we shall not remove the redundant dummies when coding a categorical variable. True or False Statement: One reason why a neural network model often requires a significant number of data observations to train is that it often has a significant number of model parameters to estimate even if there are only a few predictors. True or False. Which of the following statements about confusion matrix is wrong A) Confusion matrix is a performance measure for probability prediction techniques B) Confusion matrix is derived based on classification rules with cut-off value 0.5 C) Confusion matrix is derived based on training partition to measure a model’s predictive performance D) None of the abovearrow_forwardStudent ID is 24241357arrow_forwardWhich of the following methods help when a model suffers from high variance? a. Increase training data. b. Increase model size. c. Decrease the amount of regularization. d. Perform feature selection.arrow_forward
- 57 Formula 1 point Use shift folding, length 3, on the following value to calculate the Hash Value. 114184121 Type your answer...arrow_forwardWrite a program that reads a list of 10 integers, and outputs those integers in reverse. For coding simplicity, follow each output integer by a space, including the last one. Then, output a newline. Ex: If the input is: 2 4 6 8 10 12 14 16 18 20 the output is: 20 18 16 14 12 10 8 642 To achieve the above result, first read the integers into an array. Then output the array in reverse. 623802 1031906 nx3zmv7.arrow_forward6.3B-2. Multiple Access protocols (2). Consider the figure below, which shows the arrival of 6 messages for transmission at different multiple access nodes at times t=0.1, 0.8, 1.35, 2.6, 3.9, 4.2. Each transmission requires exactly one time unit. 1 2 3 4 t=0.0 t=1.0 t=2.0 t=3.0 5 6 t=4.0 t=5.0 For the slotted ALOHA protocol, indicate which packets are successfully transmitted. You can assume that if a packet experiences a collision, a node will not attempt a retransmission of that packet until sometime after t=5. 1 2 3 4 5 Karrow_forward
- Problem of checking Compile errors Runtime errors ======== } ng; } You have the following IQueue interface. Implement a Queue class derived from IQueue. You can use STL containers discussed in class, such as vector, queue, stack, deque, map. #include using namespace std; class IQueue { public: }; virtual void Enqueue(int val) virtual int Dequeue() = 0; virtual int Size() const = 0; int main() = 0; { Queue q; ===== } cout << q.Size() << endl; q. Enqueue(10); q.Enqueue(20); q. Enqueue(30); cout << q.Size() << endl; cout << q.Dequeue() << endl; cout << q.Size() << endl; cout << q.Dequeue() << endl; cout << q.Size() << endl; cout << q.Dequeue() << endl; cout << q.Size() << endl; ==== ====arrow_forwardlogicarrow_forwardQ1: For the Figure Below if the input to the first tank is step with magnitude 2 find 1. What type of relation between (tanks 1 and 2) and tank 3 2. Initial real value of H2, if the steady state value is 10 3. Final Value of H3 4. H1 at t=1.5 5. For the system tank1 and tank 2 only which case is applied to them (overdamping, underdamped or critically damping) A₁=1 A₂=1 Tank 1 R₁ = 2 * Tank 2 R₁₂=2 A3=0.5 hy R₁=4 Tank 3arrow_forward
- Please original work Talk about the most common challenges encountered in a data warehouse What are some creative ways to overcome those challenges What is for one real world example where your method would be effective Please cite in text references and add weblinksarrow_forwardWhat is the differences between mobile website navigation and traditional website navigation?arrow_forwardPoint 10:26 Explain P 10:26 10:25arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT