[Solved] CSE271Lab 2- Lab2InputOutput.java

$25

File Name: CSE271Lab_2-_Lab2InputOutput.java.zip
File Size: 310.86 KB

SKU: [Solved] CSE271Lab 2- Lab2InputOutput.java Category: Tag:
5/5 - (1 vote)

Write a program, Lab2InputOutput.java, that reads a file containing text.

The name of the input file will be provided by a user of your program as a (the first) command line argument to your program (see lecture 2_1 or the textbook for a reminder on command line arguments).

Prompt the user (system.in) for the name they want to use for the output file using the console.

For this part you do not need to handle the exception. Rather, you can just throws it to the main level and have the stack trace printed.

Read each line and send it to the output file, preceded by line numbers.

Example

If the input file is

Mary had a little lamb

Whose fleece was white as snow.

And everywhere that Mary went,

The lamb was sure to go!

then the program produces the output file

/* 1 */ Mary had a little lamb

/* 2 */ Whose fleece was white as snow.

/* 3 */ And everywhere that Mary went,

/* 4 */ The lamb was sure to go!

Part 2

Write a program, Lab2FloatingPoint.java, that asks the user to input a set of floatingpoint (float) values ONE AT A TIME.

When the user enters a value that is not a number, give the user a second chance to enter the value USING EXCEPTIONS by catching the appropriate exception.

After two (failed) chances in a row, quit reading input and continue the program.

Finally, add all correctly specified values and print the sum when the user is done entering data. You must use exception handling to detect improper inputs.

HINT: Follow the DataAnalyzer example from class & Textbook Section 7.5 in regards to having an outer loop with exceptions

Sample run of second part of Lab 2, demonstrating that it is two exceptions in a row.

2 4 a 4 2 a b

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CSE271Lab 2- Lab2InputOutput.java
$25