+1 (315) 557-6473 

Java Program to Read Text Parameters Assignment Solution.


Write a java assignment program to read text parameters.

Requirements and Specifications

Description: Using the current code file (attached) fix any errors or add code that is needed to ensure these instructions are met: 1. You have been asked to create a basic histogram in the following format: ^ | |***** (5) |** (2) |*************** (15) |**** (4) |***** (5) |****** (6) |************************* (25) |******** (8) |***** (5) |* (1) +----|----|----|--> The general logic (not all-inclusive) is as follows: 1. Read a text parameter/data file of 10 integers, one per line, into an array. 2. Into a text file write the following: 3. Write the upward-pointing carat “^” and one empty pipe “|” each on individual lines. 4. For each element in the array, do the following: 5. Write a pipe “|”. 6. Write the asterisk “*” as many times as specified by each integer value to create a line of asterisks using a loop. 7. Write the integer value in parentheses to the right of each asterisk bar. 8. Write the final line as one string “+----|----|----|-->” Other: ○ In addition to the file output, include console output using System.out.print for example. Doing so will assist you with debugging. Leave the console output in place in your submission. ○ You are free to vary the number of asterisks per line, within reason. ○ You will need both read and write streams for the parameter/data file and output file, respectively. ○ You will also need to open the files as well as close the files. ○ You will need to specify path and filename information for both files. ○ This Activity can be completed using one class if you prefer. ○ Include appropriate package import declarations as needed. ○ Observe proper commenting/documentation techniques. § Include clearly written comments/documentation to explain the purpose of major blocks of code. § As needed/appropriate, include additional levels of comments/documentation detail to help you understand your code and logic as well as to help your reader understand the same. ○ Observe proper naming conventions for classes, attributes, methods, etc.
Source Code
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
package mod4;
 * @author
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
public class Mod4 {
public static void main(String[] args) {
        Scanner sc = new Scanner(System.in); //accepts input of the prim data type, with input stream of OS
//prompt user for file name and load file
        System.out.println("Enter the file name for input: "); ///prompt user for input file name
        String filename = sc.nextLine();
        File doc = new File(filename); //file that has the text content to be read
        //Scanner scanner;
        int tango = 0;
        int [] numbers = new int[100];
        int counter = 0;
        String readChar = "";
        char [] iNumbers = new char[100];
        try {
            //write to file
            PrintWriter outputFile = new PrintWriter("OUTPUTMod4Histogram.txt");
            //read file using Scanner
                Scanner scanner = new Scanner(doc); //the file called for input is to be read
                while(readChar != "+"){
                    while(readChar != "^" || readChar != "|" || readChar != "("){
                        tango = tango+1;
                    numbers[counter] = tango;
            //numbers is initiated for 'count' and is also line (what is read)
            //file loaded succesfully the file called from input
            System.out.println("File loaded successfully");
            //output the starting lines of carat and pipe
            //start a for loop for number of lines to output a pipe for
            for(int i=0; i
                    //start a nested for loop for outputting the number of asterisks per line
                    for(int j=0; j
                //print the loop results to screen for output
                            + numbers[i]
                            + ")\n"
                //send the loop results to the output file
                            + numbers[i]
                            + ")\n"
        //output the final lines to screen and file
        //output the closure steps for the file export and try close
        System.out.println("Output exported to OUTPUTMod4Histogram.txt");
        //error handling if file cannot be found
        catch (FileNotFoundException e){
            System.out.println("file not found");