Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 1: In a class called Stats (template is provided), given a text file of doubles (see this labs Canvas page for a sample file),

Part 1:

In a class called Stats (template is provided), given a text file of doubles (see this labs Canvas page for a sample file), write a program that determines the average, the maximum, the minimum and how many numbers are in the following buckets: less than 0, between 0 (inclusive) and 100 (exclusive), and greater than or equal to 100.

Your program should print the following message to another file called fileOut.txt:

 Statistics for the numbers in fileIn.txt: average: max: min: There are negative numbers, numbers between 0 (inclusive) and 100 (exclusive), and numbers that are greater than or equal to 100.

Here is starter code for part 1:

package com.company; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner; public class Main { public static void main(String[] args) throws IOException { // Scanner and PrintWrite must be declared outside the try block  // otherwise their scope will be limited to within the block  Scanner input = null; double inputNumber = 0.0; int negNum = 0; int btw0and100 = 0; int geq100 = 0; int lineCounter = 0; double grandTotal = 0.0; double min = 0.0; double max = 0.0; double average = 0.0; try { input = new Scanner(new FileInputStream("fileIn.txt")); } catch (IOException e) { System.out.println("File not found."); System.exit(0); } input.close(); display(average, max, min, lineCounter, negNum, btw0and100, geq100); } public static void display (double average, double max, double min, double lineCounter, int negNum, int btw0and100, int geq100){ PrintWriter output = null; try{ output = new PrintWriter(new FileOutputStream("fileOut.txt")); } catch (IOException e) { System.out.println(" Sorry, we cannot locate the file!"); System.exit(0); } output.close(); } }

Part 2:

In a class called Diary (template is provided), write a program that prompts users to enter the date as three integers separated by spaces (i.e mm dd yyyy) then it prompts them enter as many lines of prose they wish (for their to-dos list or diary entry). Your program should store their entries at the end of a file called diaryLog.txt and old data should NOT be erased. Each entry should be formatted as follows (example for a diary entry entered on 7/14/2017):

 ...old stuff. Date: 07/14/2017 Dear diary, today we had a midterm. I think it went ok, ..

Starter Code for Part 2:

public class Diary

{

public static void main(String[] args) throws IOException {

// Needed variables

int mm = 0;

int dd = 0;

int yyyy = 0;

String prose = ""; //Empty string to read prose

FileOutputStream fos = null;

PrintWriter output = null;

Scanner keyboard = new Scanner(System.in);

System.out.println("Enter the date as three integers separated by

spaces (i.e mm dd yyyy) ");

mm = keyboard.nextInt();

dd = keyboard.nextInt();

yyyy = keyboard.nextInt();

System.out.println("Enter as many lines of prose you wish (for your

to-do

s list or diary entry)");

System.out.println("Press CTRL + Z to end your entry");

//START YOUR CODE HERE

}

}

Part 3:

Write a program Advice.java that gives and takes advice on program writing. The program starts by writing a piece of advice to the screen and asking the user to type in a different piece of advice. The program then ends.

The next person to run the program receives the advice given by the person who last ran the program.

The advice is kept in a text file advice.txt and the content of the file changes after each run of the program. Furthermore, you should have another text file called adviceLog.txt, which starts off blank but with each run of the program it logs the advice that was given (without deleting the previous advices). You should allow theuser to type in advice of any length so that it can be any number of lines long. The user is told to end his orher advice by pressing the Return key two times. Your program can then test to see that it has reached the end of the input by checking to see when it reads an empty string "".

Input file: advice.txt

Note: Please use basic code to write these. I cannot understand advanced Java skills

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions

Question

5. Our efficiency focus eliminates free time for fresh thinking.

Answered: 1 week ago