Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have tried a few routes with the Math_Results.csv and the results still will not populate in Excel. Any idea what can be the issue.

I have tried a few routes with the "Math_Results.csv" and the results still will not populate in Excel. Any idea what can be the issue. Was I supposed to create the folder under myjava or on excel?

import java.io.File;

import java.util.Scanner;

import java.io.FileWriter;

public class MathOP5 {

public static void main(String[] args)

{

Scanner in = new Scanner(System.in); // Scanner object

File file = new File("Math_Results.csv"); //Referal to Math_Results.csv

System.out.print("name?: "); // Scan users name

String name = in.nextLine();

System.out.println("Hello \"" + name + "\"");

System.out.print("Do you want to save the results (Y/N)? "); // Ask if results should be saved

String saveResult = in.nextLine();

System.out.print("numbers to average? "); // Numbers to average

int n = in.nextInt();

double average = 0;

System.out.print("Input " + n + " numbers: ");

String expression = ""; // If yes is selected, an expression will be shown

for(int i = 0; i < n; ++i)

{

double temp = in.nextDouble(); // User inmput n will be combined in average

average += temp;

if(saveResult.equals("Y")){ // Do you want to save results ?

if(i

expression = expression+temp+" + ";

else if(i==n-1) // Is this the last number entered?

expression = expression+temp+" = "+average;

}

}

// save results in csv file Y/N

if(saveResult.equals("Y")){

try{

FileWriter myWriter = new FileWriter(file);

myWriter.write(expression);

myWriter.close();

}

catch(Exception e){

System.out.println("Error");

}

}

average /= n; // Calculate average

System.out.printf("The average is %.2f ", average);

// Does the user want to review the results

// If yes, then open the file and read the content

System.out.print(" Do you want to review the results (Y/N)? ");

String reviewResults = in.nextLine();

reviewResults = in.nextLine();

if(reviewResults.equals("Y")){

try{

Scanner sc = new Scanner(file);

System.out.println("Results form Math_Results.csv");

while (sc.hasNextLine()){

System.out.println(sc.nextLine());

}

}

catch(Exception e){

System.out.println("Error");

}

}

}

}

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 3 Lnai 9286

Authors: Albert Bifet ,Michael May ,Bianca Zadrozny ,Ricard Gavalda ,Dino Pedreschi ,Francesco Bonchi ,Jaime Cardoso ,Myra Spiliopoulou

1st Edition

3319234609, 978-3319234601

More Books

Students also viewed these Databases questions

Question

Name the four major categories of material handling equipment.

Answered: 1 week ago

Question

Define a relational DBMS and explain how it organizes data.

Answered: 1 week ago

Question

4. What decision would you make and why?

Answered: 1 week ago