Problem 1. A file that contain two columns of data are provided. You should write a program that calculate the average of the two number in each row, and output them into a separate file. Some row contains non-numbers or may be missing an number, and your code should use Exception to catch these errors, and output an appropriate error message.
For testing, your input data file should be:
1.2 3.5
one 4.4
2.5 three
4.1 9.9
1.9
18.5. 20.3
Please find the code below:::
ReadFileAndGetAverage.java
package fileIO;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
public class ReadFileAndGetAverage {
public static void main(String[] args) {
Scanner sc = new
Scanner(System.in);
String inputFileName =
"input.txt";
String outputFileName =
"output.txt";
File file = new
File(inputFileName); //reading data from this file
Scanner reader;
System.out.println("Opening file
"+inputFileName+" ....");
String line="";
try {
//for writing to
file
PrintWriter
outputFile = new PrintWriter(outputFileName);
//read file
using scanner
reader = new
Scanner(file);
while(reader.hasNextLine()){
//read line
try{
line =
reader.nextLine();
System.out.print("Processing
line : "+line);
String datas[] = line.split("
");
double num1 =
Double.parseDouble(datas[0]);
double num2 =
Double.parseDouble(datas[1]);
double average = (num1+
num2)/2;
System.out.println(" :
Average : "+average);
outputFile.write(average+"\n");
}catch(Exception e){
System.out.println("
Exception while read line "+line);
}
}
outputFile.close();
System.out.println("Data exported to file "+outputFileName+"
successfully!!!");
} catch (FileNotFoundException e)
{
System.out.println("file not found");
}
sc.close();
}
}
output:
Problem 1. A file that contain two columns of data are provided. You should write a...
Write a program that loads a file called "sample.txt" in read mode, reads its content, and closes the file. Use exception handling to catch any errors. 2. Compute the letter and punctuation distribution in the file. That is, output the number of a’s, the number of b’s, etc. and the number of commas, dashes, and periods. Ignore case when computing this, so ‘A’ and ‘a’ are the same letter. Use lists. 3. Compute the number of words in the file....
Write a class that analyzes data you have stored in a text file. Your data represents the ages of the individuals in your fictitious community. The data is stored, one per line, in a text file. For example, File name: myData.txt Contents: 45 18 6.5 3 5 sdtypo# 18 10 The number of lines in your text file must fall somewhere between 20 and 100 lines. Some of the lines must hold character strings that are not convertible to integers,...
Need help with code in C# Create an application that reads a file named Accounts.txt. Your application should load the file and display back the results. The application should allow the user to enter additional entries and save them back to the same file. The CSV file should contain the following fields: AccountName, InvoiceDate, DueDate, AmountDue If the CSV file contains invalid data you want to inform the user which row contained bad data. Below is an example of what...
Python 3:In this problem, your input file will contain a number of ciphertext and key pairs, separated by a space. You may assume that the ciphertext contains only uppercase letters. However, it is possible that the key may be missing, and your program should handle this case. The ciphertext has been encrypted by shifting letters in the alphabet by the amount specified by the key. The word HELLO with key = 2 becomes JGNNQ. Letters should wrap around, so PIZZA...
Must be written in JAVA Code Write a program that will read in a file of student academic credit data and create a list of students on academic warning. The list of students on warning will be written to a file. Each line of the input file will contain the student name (a single String with no spaces), the number of semester hours earned (an integer), the total quality points earned (a double). The following shows part of a typical...
The input file should contain (in order): the weight (a number greater than zero and less than or equal to 1), the number, n, of lowest numbers to drop, and the numbers to be averaged after dropping the lowest n values. The program should also write to an output file (rather than the console, as in Horstmann). So you should also prompt the user for the name of the output file, and then print your results to an output file...
Please provide the full code...the skeleton is down below: Note: Each file must contain an int at the beginning, stating the number of records in the file. Afterwards, the number of records in the file will follow. Each record that follows will consist of a last name (String), and a gpa (double). However, to test the error handling of your program, the number of records will not always match the int value. All possible combinations should be tested. 1.) Prompt...
FOR JAVA Write a program that takes two command line arguments: an input file and an output file. The program should read the input file and replace the last letter of each word with a * character and write the result to the output file. The program should maintain the input file's line separators. The program should catch all possible checked exceptions and display an informative message. Notes: This program can be written in a single main method Remember that...
Please use C++. Write a class named Circle that has a double data member named radius and a static double data member named maxRadius. It should have a default constructor that initializes the radius to 1.0. It should have a constructor that takes a double and uses it to initialize the radius. It should have a method called calcArea that returns the area of the Circle (use 3.14159 for pi). It should have a static set method for the maxRadius....
Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...