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)
- PLEASE SOLVE STEP BY STEP WITHOUT ARTIFICIAL INTELLIGENCE OR CHATGPT I don't understand why you use chatgpt, if I wanted to I would do it myself, I need to learn from you, not from being a d amn robot. SOLVE STEP BY STEP I WANT THE DIAGRAM PERFECTLY IN SIMULINKarrow_forwardI need to develop and run a program that prompts the user to enter a positive integer n, and then calculate the value of n factorial n! = multiplication of all integers between 1 and n, and print the value n! on the screen. This is for C*.arrow_forwardI need to develop and run a C* program to sum up integers from 1 to 100, and print out the sum value on the screen. Can someone help please?arrow_forward
- Given the schema below for the widgetshop, provide a schema diagram. Schema name Attributes Widget-schema Customer-schema (stocknum, manufacturer, description, weight, price, inventory) (custnum, name, address) Purchased-schema (custnum, stocknum, pdate) Requestedby-schema (stocknum, custnum) Newitem-schema (stocknum, manufacturer, description) Employee-schema (ssn, name, address, salary) You can remove the Newitem-schema (red).arrow_forwardTrue or False: Given the sets F and G with F being an element of G, is it always ture that P(F) is an element of P(G)? (P(F) and P(G) mean power sets). Why?arrow_forwardCan you please simplify (the domain is not empty) ∃xF (x) → ¬∃x(F (x) ∨ ¬G(x)). Foarrow_forward
- HistogramUse par(mfrow=c(2,2)) and output 4 plots with different argument settings.arrow_forward(use R language)Scatter plot(a). Run the R code example, and look at the help file for plot() function. Try different values for arguments:type, pch, lty, lwd, col(b). Use par(mfrow=c(3,2)) and output 6 plots with different argument settings.arrow_forward1. Draw flow charts for each of the following;a) A system that reads three numbers and prints the value of the largest number.b) A system reads an employee name (NAME), overtime hours worked (OVERTIME), hours absent(ABSENT) and determines the bonus payment (PAYMENT).arrow_forward
- Scenario You work for a small company that exports artisan chocolate. Although you measure your products in kilograms, you often get orders in both pounds and ounces. You have decided that rather than have to look up conversions all the time, you could use Python code to take inputs to make conversions between the different units of measurement. You will write three blocks of code. The first will convert kilograms to pounds and ounces. The second will convert pounds to kilograms and ounces. The third will convert ounces to kilograms and pounds. The conversions are as follows: 1 kilogram = 35.274 ounces 1 kilogram = 2.20462 pounds 1 pound = 0.453592 kilograms 1 pound = 16 ounces 1 ounce = 0.0283 kilograms 1 ounce = 0.0625 pounds For the purposes of this activity the template for a function has been provided. You have not yet covered functions in the course, but they are a way of reusing code. Like a Python script, a function can have zero or more parameters. In the code window you…arrow_forwardmake a screen capture showing the StegExpose resultsarrow_forwardWhich of the following is not one of the recommended criteria for strategic objectives? Multiple Choice a) realistic b) appropriate c) sustainable d) measurablearrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,New Perspectives on HTML5, CSS3, and JavaScriptComputer ScienceISBN:9781305503922Author:Patrick M. CareyPublisher:Cengage LearningNp Ms Office 365/Excel 2016 I NtermedComputer ScienceISBN:9781337508841Author:CareyPublisher:Cengage