THINK FIRST·CODE LATER

← All labs

CharTools: write your own Character utility class

Problem

Java's Character class is a utility class: only static methods, and no objects. Write your own, CharTools, without calling Character:

isDigit, isUpperCase, isLowerCase, isLetter, toUpperCase, toLowerCase and digitValue ('7' gives 7; a character that is not a digit gives −1).

Make it impossible to create a CharTools object: declare the class final with a private constructor.

The public class CharToolsApp reads one line and prints the number of letters (and how many are capitals), the number of digits and their sum, the number of other characters, and the line with the case of every letter swapped. For the input

Room B214, Floor 3!

the program prints

Letters: 10 (3 capital)
Digits: 4, their sum: 10
Other characters: 5
Case swapped: rOOM b214, fLOOR 3!

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

l12-7-data-1.txt

Room B214, Floor 3!
What your program must print for l12-7-data-1.txt
Letters: 10 (3 capital)
Digits: 4, their sum: 10
Other characters: 5
Case swapped: rOOM b214, fLOOR 3!

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < l12-7-data-1.txt

Windows PowerShell does not understand <:

Get-Content l12-7-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.