ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 9 Weeks Ago, 1 Day Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 08 May 2017 My Price 11.00

create a program that uses a MathInput.cvs file

I need to create a program that uses a MathInput.cvs file. It needs to take the data in this file and calculate and send the results to the output file MathOutput.csv .

The results should be something like this for the first set in the output file “MathOutput.csv”.  Notice that the format included the name of the operation. followed by the number, then the word Total”,  followed by the result of the operation.  At the end of a set of operations, your program should include a summary line with the text “Number of elements = ”, then the actual number of elements, followed by the text “Total = “, followed by the calculated total of the operations, followed by the text “Average = “ followed by the calculated average.  Between each set of output, display a line of *. See the example below:

Add           2      Total          2

Add           6      Total          8

Subtract     9      Total         -1

Multiply    10      Total         -10

Number of elements = 4, Total = -10, Average = -2.5

********************************************

Divide        4      Total  0

Multiply      5      Total 0

Subtract     6      Total -6

Number of elements=3, Total = -6, Average = -2

********************************************

I have attached the MathInput.cvs file and my attempt on the src code. I need help with the rest please. 

 

 

/************************Name:Krystal IguinProgram name: FinalProject.javaDate: 11/27/2016Purpose: Create a program(s) that uses an input file and creates an output file************************/import java.util.Scanner;import java.io.*;import java.util.*;import java.io.IOException;public class FinalProject {public static void main(String[] args) throws IOException {try(FileReader read = new FileReader("MathInput.csv")){BufferedReader buffRead = new BufferedReader(read);FileWriter write = new FileWriter("MathOutput.csv",true);BufferedWriter buffWrite = new BufferedWriter(write);while ((line = buffRead.readLine()) != null) {String[] value = line.split(",");operator[i] = value[1];number[i] = (Integer.parseInt(value[0])); //Change from a string to aninteger//determines the operator to do the math operation and write to theoutput fileif (operator[i].equals("+")){total = total + number[i];buffWrite.write("Add " + number[i] + " total " + total);buffWrite.newLine();}if (operator[i].equals("-")){total = total - number[i];buffWrite.write("Subtract " + number[i] + " total " + total);buffWrite.newLine();}if (operator[i].equals("*")){total = total * number[i];buffWrite.write("Multiply " + number[i] + " total " + total);buffWrite.newLine();}if (operator[i].equals("+")){total = total / number[i];buffWrite.write("Divide " + number[i] + " total " + total);buffWrite.newLine();}System.out.print("Number of elements = " + elements + ", Total= " + total + ", Average = " + average );//Outputs element, total, averageamountstotal=0;String choice = s.nextLine();

}}catch (IOException e){//Catch output Error messageSystem.out.println("I/O Error: " + e);}/*public void closeFile(){x.close();}*/}}

 

Answers

(11)
Status NEW Posted 08 May 2017 03:05 AM My Price 11.00

-----------

Not Rated(0)