Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help in JAVA please Part 4: Create method divideFromFile() 1. Create a file called myTestFile. txt in your project folder (not in the same folder

Help in JAVA please

image text in transcribed

Part 4: Create method divideFromFile() 1. Create a file called myTestFile. txt" in your project folder (not in the same folder as your .java files). In that file, put two double values separated by commas, for example, 3.0,1.5". 2. Write method with the header public static void divide FromFile()". In that method, do the following steps: a. Ask the user for a filename. b. Open the file specified by the user. If the file does not exist, then ask the user for a filename again. Keep asking until they input a valid filename. Read the two numbers from the file. If there is anything wrong with the file, such as not containing two numbers, containing Strings, etc., then print out The file did not contain valid data. Otherwise, print out the quotient of the first number divided by the second number. 3. Use try-catch blocks when opening the file to ensure that it exists. 4. Use try-catch blocks when reading from the file to make sure the data is what you expect. C. To open a File in your program, use the following code: File myFile = new File (fileName); // fileName should be a String. It needs to have the file extension included Scanner fileScan = new Scanner (myFile)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro PowerShell For Database Developers

Authors: Bryan P Cafferky

1st Edition

1484205413, 9781484205419

More Books

Students also viewed these Databases questions

Question

What are some common causes of unethical behavior in the workplace?

Answered: 1 week ago