Question

please read directions first. this is supposed to be a hybrid programe add comments please JAVA...

please read directions first. this is supposed to be a hybrid programe

add comments please

JAVA

please add comments

Programming Project 1 and Programming Project 2 "Hybrid"

Your goal is to write a program that combines the functionality of both Programming Project 1andProgramming Project 2 into a single program. That is, your program should read a file ( Numbers.txt) of numbers of type double that contains some duplicates and is ordered smallest to largest. Your program should ignore the duplicate values and determine the smallest, largest and average of the remaining values. Your program should lastly output the smallest, largest and average values to an output file (results.txt).

Name your project " RealNumbersNoDuplicatesHighLowAverageText"  Your program must check for and handle exceptions including (FileNotFoundException when opening the file, and IOException when opening the files, writing numbers to a file and when closing a file).  Numbers.txt contains the data that your program should process. Remember to use appropriate naming conventions, include a well written program header comment, package your solution files into a single compressed/ZIP file, and submit the resulting file using this Assignment tool by the submission due date.

Programming Project 1

Write a program that searches a file of numbers and displays the largest number, the smallest number and the average of all the number in the file. Do not assume that the number in the file are in any special order. Your program should obtain the file name from the user. Use either a text file or a binary file. For the text-file version, assume one number per line. For the binary-file version, use numbers of type double that are written using writeDouble.

Programming Project 2

Write a program that reads a file of numbers of type int and outputs all the numbers to another file, but without any duplicate numbers. Assume that the numbers in the input file is already ordered from smallest to largest. After the program is run, the new file will contain all the numbers in the original file, but no number will appear more than once in the file. The numbers in the output file should also be sorted from smallest to largest. Your program should obtain both file names from the user. Use either a text file or a binary file. for the text-file version, assume one number per line. for the binary-file version, use numbers of typeint that are written using writeInt.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Programming Project 1

import java.util.*;
import java.io.*;
public class FileIn
{public static void main(String[] args)throws FileNotFoundException
{String filename;
Scanner in=new Scanner(System.in);
System.out.print("Enter file name: ");
filename=in.nextLine();
Scanner input=new Scanner(new File(filename));
int count=0;
int sum=0,num, max,min;
double average;
System.out.println("The numbers in the file are: ");
max=input.nextInt();
min=max;
num=max;
sum=max;
count++;
System.out.print(num+" ");
while(input.hasNextInt())
    {num=input.nextInt();
    System.out.print(num+" ");
    sum+=num;
    if(num>max)
         max=num;
    if(num<min)
         min=num;
    count++;
     }
System.out.println("\nThe smallest number is "+min);
System.out.println("The largest number is "+max);
average=sum/(double)count;
System.out.println("The average of the numbers is "+average);
           

}
}

Sample Output:

Enter the file name sample txt The largest number is : 34.0 The smallest number is : 4.0 The average number is 15.75

Input file name is sample.txt

in that file the numbers are

12

13

4

34

Add a comment
Know the answer?
Add Answer to:
please read directions first. this is supposed to be a hybrid programe add comments please JAVA...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PLEASE HELP C++ some of the content in random.txt Program #2 This problem is a modification...

    PLEASE HELP C++ some of the content in random.txt Program #2 This problem is a modification of Problem 24 on page 302 of the Gaddis text with two small additions. (A scan of this problem can be found on the last page of the assignment.) In this assignment, your program will read in a list of random numbers from an input file, random. txt (found on eLearning in the "Homework Input Files" folder), and calculate the following statistics on those...

  • PLEASE INCLUDE COMMENTS In java Create a Java Program Add the following comments at the beginning...

    PLEASE INCLUDE COMMENTS In java Create a Java Program Add the following comments at the beginning of the file: Your name. The name of the class(es) used in the program. The core concept (found below) for this lesson. The date the program was written. Include a recursive method separate from the main method that will add together all of the even numbers between and including 1 and the value the user supplies. For instance, if the user enters 10 then...

  • Write a program to read the contents of data.txt file, and determine the smallest value (min),...

    Write a program to read the contents of data.txt file, and determine the smallest value (min), largest value (max), and the average value (ave). The minimum, maximum, and average values must be calculated in the function calc(). Remember to declare the stdlib.h library, so that you can use the atof function, which will convert the number in the text file into float number. Also, remember to check if there is an error opening the file or not. If there is...

  • C programming. please include comments In this lab, you will learn to read data from and...

    C programming. please include comments In this lab, you will learn to read data from and write data to a file - another use for pointers. SAMPLE PROGRAM There are two sample programs this week - WriteFile.c and ReadFile.c. The first, WriteFile.c, allows the user to enter customer names (first, middle, and last), and writes each name to an output text file, customerNames.txt. formatted as: firstName middlelnitial lastName" After you've run it once, what happens to the names you added...

  • please use c++ please write down the input file information please add comments for some codes...

    please use c++ please write down the input file information please add comments for some codes please do not use #include <bits/stdc++.h> we did not learn it yet thank you CSIT 575-Take Home Lab #11: Arrays To learn to code, compile and run a program processing characters. Assignment Plan and code a top-down modular program utilizing ARRAYS to solve the following problem, using at least 3 functions (called from the main() section or from another function) to solve the problem....

  • Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The progra...

    Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs opening any of the 3 For example, (user input shown in caps in first line) Enter first...

  • Please give me all necessary screenshot and comments. (I use Eclipse) Thanks Assume a system has...

    Please give me all necessary screenshot and comments. (I use Eclipse) Thanks Assume a system has 32-bit virtual memory address with a 4-KB page size. Write a program that is passed a virtual address (in decimal) and outputs the page number and offset for the given address. The output should look like: The address 19986 contains:       Page number = 4       Offset = 3602 Your driver should pass the program three numbers: 19986, 347892, and 5978. Note the program...

  • Part B: Java Programming Problems. Choose 2 of the following problems. Each solution is worth 20...

    Part B: Java Programming Problems. Choose 2 of the following problems. Each solution is worth 20 marks. You are expected to use comments in your code. Marks will be deducted for incorrect brackets, syntax etc, so be careful as possible (40 marks). 1. Create a new program that: • Reads a sentence from a file; Writes the sentence to another file in reverse; and • Prints a message to the user in a JOptionPane message box when finished. 2. Write...

  • For this assignment you are to create two programming projects. The first should have a project...

    For this assignment you are to create two programming projects. The first should have a project directory with Lab02-2WriteNumbers and the second should have a project directory with Lab02-2ReadNumbers. Lab02-03WriteNumbers – Write a program that asks the user to enter five numbers. Use a double data type to hold the numbers. The program should create a file and save all five numbers to the file. Enter a number (1 of 5): 45 Enter a number (2 0f 5): 23 Enter...

  • please put the comment each line, make sure i will have output too. write a program,...

    please put the comment each line, make sure i will have output too. write a program, Summarize (Summarize.java), containing the main() method, that first writes 10,000 random positive double type numbers, to the full accuracy of the number (15/16 decimal places), to a text file named DataValues.txt, one number per line. The program must then close that file, and reopen it for reading. Read back the values from the file and write the following information to a file named Summary.txt:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT