For this exercise, you will create 2 classes: InputOutput class and AddNumbers class. ⦁ InputOutput Class: write a program that carries out the following tasks: ⦁ Create an object of type PrintWriter and that writes into a file with the name greeting.txt. ⦁ Print the message “Hello, world!” on the file. ⦁ Close the file. ⦁ Open the same file again. ⦁ Read the message into a string variable (hint: use nextLine() method to read the text). ⦁ Print the message on the screen. ⦁ AddNumbers Class: write a program that asks the user to input four floating-point numbers. Add all correctly specified values and print the sum when the user is done entering data. Use exception handling to detect improper inputs. For example, the user might enter letters instead of numbers. In this case, use the exception handling mechanism to print a proper message. (hint: use InputMismatchException) Don’t forget to import java.util.*.
For this exercise, you will create 2 classes: InputOutput class and AddNumbers class.
⦁ InputOutput Class: write a program that carries out the following tasks:
⦁ Create an object of type PrintWriter and that writes into a file with the name greeting.txt.
⦁ Print the message “Hello, world!” on the file.
⦁ Close the file.
⦁ Open the same file again.
⦁ Read the message into a string variable (hint: use nextLine() method to read the text).
⦁ Print the message on the screen.
⦁ AddNumbers Class: write a program that asks the user to input four floating-point numbers. Add all correctly specified values and print the sum when the user is done entering data. Use exception handling to detect improper inputs. For example, the user might enter letters instead of numbers. In this case, use the exception handling
Trending now
This is a popular solution!
Step by step
Solved in 7 steps with 5 images