Question
Another introductory java coding question (File reading): Note: You will be coding in intelliJ as your development environment for this program and then copying and
Another introductory java coding question (File reading):
Note: You will be coding in intelliJ as your development environment for this program and then copying and pasting your .java file to Zybooks for scoring.
Introduction:
In this program, you will read an external txt file that contains some numbers and other tokens in your program and then compute whether the data contains any three digits Armstrong number or not.
What is an Armstrong Number? An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is an Armstrong number since 3^3+7^3+1^3 = 371.
File Processing:
You are to read the input file, print out all the 3 digits Armstrong numbers and then create a report having the following information:
Number of Armstrong nums in the file.
Number of Non-Armstrong nums in the file.
Number of tokes in the file (non-integers).
Required Decomposition
Required constants - You must declare a constant to hold the filename. You may declare other constants as you deem appropriate:
public static final String FILENAME = "somedata.txt"; //name of input file -- DO NOT MODIFY
File getInputFile(Scanner console) - This method will prompt the user for the path where the input file is located. In IntelliJ, the path may be iofiles/ or data/as we discussed in lecture. Note that in Zybooks, the path is not needed so the user will just enter a carriage return to indicate there is no path needed. Validation: You must first verify that the file exists. If the file cannot be found at the designated location, you should re-prompt for the path to the input file. Once you have determined the file exists, this method will display "(name of the file) successfully found." before returning back to the main() (see sample run).
boolean isArmstrong(int number) - This method accepts a number and returns true if the number is an Armstrong number and false otherwise. An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself.
void displayReport(File file, int armNum, int nArmNum, int badToken) - Called from main and accepts four parameters - file object reference, and final counts of Armstrong numbers, Non- Armstrong numbers and bad tokens and displays final report as shown in sample run.
Sample test run:
Enter path for the file "somedata.txt"? Cannot find that file. Resubmit
Enter path for the file "somedata.txt"? somedata.txt successfully found.
Scanning somedata.txt...
Number : 153 is an Armstrong number.
Number : 407 is an Armstrong number.
Number : 371 is an Armstrong number.
Number : 370 is an Armstrong number.
Final Report for data.txt File Length (in bytes): 117
The file has 4 Armstrong numbers.
The file has 12 non-Armstrong numbers.
The file has 5 tokes.
Code can be found at:
https://openload.co/f/GZm64jKDuzk/somedata.txt.txt
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started