Reference no: EM13944626
Write a simple text formatting program in Java, that will read words from an input file and write them to an output file, removing extra whitespace and filling each line with as many words as will fit up to a maximum column width (similar to a column of text in a newspaper). The maximum column width, input text file name, and output text file name are entered interactively when the program starts.
The program needs to perform the following activities:
* Prompt for the maximum formatted output width. The range is 30 to 100 characters.
* Prompt for the file name of the input text file. Test that the file exists, and can be read. If so, then only open the file for reading. Repeat these steps until a valid input file is entered.
* Prompt for the file name of the output file to write the formatted words to. Test that the file does not already exist, and if it does, prompt to check for overwriting the file. Repeat these steps until a valid output file is entered.
* Write a line of * characters, the width of the formatted output, as a heading in the output file (no formatted output line should be longer than this heading line), for example, if 45 was entered as the maximum output width, this line should have 45 * characters.
* Read words (text between whitespace) from the input file, appending them to a line of text being formatted, with one space character between words. Keep appending words until the current word would cause the line to become longer than the output column width. If so, write the line to the output file, reset it to contain just the new word, and continue reading. Continue reading until the end-of-file is encountered.
* Do not read the entire file into memory, and do not use an array to hold multiple lines in memory.
Attached are sample input-output, and two sets of test data that should be run with a width of 40 and width of 70.
Attachment:- Sample output.zip
What is the weighted average pre tax cost of capital
: A company has a market value of $500 million. It has a market value of equity of of $200 million, a market value of long term debt of $150 million and a market value of short term ebt of $150 million. The cost of equity is 12% the cost of long term d..
|
Prepare the variable costing format income statement
: Dallas Gourmet Grocery (Dallas) expects to have the following financial accounting income statement for the current year, Prepare the variable costing (contribution margin) format income statement for Dallas
|
What must the beta be for the other stock in your portfolio
: You own a portfolio equally invested in a risk-free asset and two stocks. If one of the stocks has a beta of 1.55, and the total portfolio is exactly as risky as the market, what must the beta be for the other stock in your portfolio?
|
Contemporary organisational structure
: Understanding contemporary organisational structures and contemporary people management practices.
|
Write a simple text formatting program in java
: Prompt for the maximum formatted output width. The range is 30 to 100 characters.
|
What is cost of common equity
: Percy Motors has a target capital structure of 30% debt and 70% common equity, with no preferred stock. The yield to maturity on the company's outstanding bonds is 8%, and its tax rate is 40%. Percy's CFO estimates that the company's WACC is 15.00%. ..
|
Distribution of total body protein in adult men
: The distribution of total body protein in adult men with liver cirrhosis is approximately Normal with mean 9.8 kg and standard deviation 0.1 kg. Reference: Ref 11-5 What is, approximately, the probability that a randomly selected man with liver ci..
|
What should the share price be in one year
: A share of stock sells for $44 today. The beta of the stock is 1.6, and the expected return on the market is 12 percent. The stock is expected to pay a dividend of $.70 in one year. If the risk-free rate is 4.3 percent, what should the share price be..
|
What is the beta of your portfolio
: You own 500 shares of Stock A at a price of $60 per share, 405 shares of Stock B at $80 per share, and 500 shares of Stock C at $41 per share. The betas for the stocks are .8, 1.8, and .7, respectively. What is the beta of your portfolio?
|