


Hi, below is the complete program ReadFromFile.java along with Man class. As instructed, None of the Stream APIs re used in the program. In fact, I have used Java.nio.file.Files class to read from the file and store it in list. Prograam is very simple and I have also place comments wherever required. I have also attached input.txt file and the output of the program for reference .
ReadFromFile.java
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
//Class to read From a File and Store the contents in a List
public class ReadFromFile {
List<String> list = null;
int count; //To count total numbers in the file
int uniqueNumbers; //To count total number of unique numbers in the file
int maxLength; //To indicate length of longest line
int sumOfEven; //To indicate sum of all even numbers
boolean areAllEven; //Boolean to check if all numbers are even or not
public ReadFromFile() {
this.list = new ArrayList<String>();
this.count = 0;
this.uniqueNumbers = 0;
this.maxLength = 0;
this.sumOfEven = 0;
this.areAllEven = true;
}
/* Method to read a file line by line
* Parameters: File object Return Type: Arrylist
* Uses readAllLines method of Java.nio.file.Files class to read from
* a file whose path is given as parameter and stores the contents in a list
*/
public ArrayList<String> read(File F){
try {
list = Files.readAllLines(Paths.get(F.getAbsolutePath()), StandardCharsets.UTF_8);
} catch (IOException e) {
e.printStackTrace();
}
//Set to store unique numbers. If duplicates are occurring they wont
//be stored in the Set, so Set will contain unique numbers
//Which can be used to count number of Unique numbers in the file
Set<String> uniqueSet = new HashSet<>();
for (String string : list) {
//For each line, if length is less than maxLength
//store the length of line in maxLength
if(maxLength < string.length())
maxLength = string.length();
//Split the numbers separated by , and count total numbers
String[] numbers = string.split(",");
count += numbers.length;
for (String number : numbers) {
//add each number to set
uniqueSet.add(number);
int num = Integer.parseInt(number);
//If number is not even set areAllEven to flse
//else add the even number to sumOfEven
if(num % 2 != 0)
areAllEven = false;
else
sumOfEven += num;
}
}
uniqueNumbers = uniqueSet.size();
return (ArrayList<String>) list; //Return ArrayList
}
public List<String> getList() {
return list;
}
public int getCount() {
return count;
}
public int getUniqueNumbers() {
return uniqueNumbers;
}
public int getMaxLength() {
return maxLength;
}
public int getSumOfEven() {
return sumOfEven;
}
public boolean isAreAllEven() {
return areAllEven;
}
}
Reader.java(Main Class)
import java.io.File;
import java.util.ArrayList;
public class Reader {
public static void main(String[] args) {
ReadFromFile readFromFile = new ReadFromFile();
File file = new File("input.txt");
ArrayList<String> list = readFromFile.read(file);
System.out.println("Total Numbers in File= " + readFromFile.getCount());
System.out.println("Total Number of Unique Numbers in File= " + readFromFile.getUniqueNumbers());
System.out.println("Length of Longest Line= " + readFromFile.getMaxLength());
System.out.println("Sum of Even Numbers= " + readFromFile.getSumOfEven());
System.out.println("Are All Elements Even? " + readFromFile.isAreAllEven());
System.out.println("Contents of the File: ");
System.out.println(list.toString());
}
}
input.txt
10,64,58,69,6,15,56,548,85,65 20,52,15,52,36,7,26,4 33,12,67,369,63,21,76,7 36,23,153,463,5,4,62,12,33 2,45,177,4,63,78,41 12,36,47,63,5,99,455,89,12,45,36 24,1,30,-2,96,47,25,36
Program Output:
Total Numbers in File= 61 Total Number of Unique Numbers in File= 43 Length of Longest Line= 32 Sum of Even Numbers= 1498 Are All Elements Even? false Contents of the File: [10,64,58,69,6,15,56,548,85,65, 20,52,15,52,36,7,26,4, 33,12,67,369,63,21,76,7, 36,23,153,463,5,4,62,12,33, 2,45,177,4,63,78,41, 12,36,47,63,5,99,455,89,12,45,36, 24,1,30,-2,96,47,25,36]
Use java. Must use streams also but not the max or some other functions noted in...
use java streams to find a general integral using simpsons method. use paralell streams if possible.
C++ Functions & Streams Write a program that will demonstrate some of the C++ Library Functions, Stream Manipulators, and Selection Control Structures. The user will be given a menu of four choices. They can input a 1 for finding Cosines, 2 for finding Logarithms, 3 for converting between Decimal and Hexadecimal, or 4 to change the format of a cstring date. You must use the proper functions and/or stream manipulators to find the answers. If the user picks the cosine,...
Using Java, create functions that return specific values listed below. MUST use integer only, functions, loops, conditionals. Money has to be stored as two different integers, one integer for dollars and another for cents. No use of double : String moneyToString(int d, int c); // Returns the Money as words. Ex, moneyToString(10,24) => "$10.24" int biggestMoney(int d1, int c1, int d2, int c2, int d3, int c3); // Returns which money is biggest. Ex, biggestMoney(10,24,3,90,1,23) => 1 Ex, biggestMoney(3,90,1,23,10,24) =>...
Python Homework: - NOTE - Must not use built-in functions (other than the range() function), slice expressions, list methods (other than the append() method) or string methods in your solution. Write a function called reverse(my_list, number=-1) that takes a list and a number as parameters. The function returns a copy of the list with the first number of items reversed. Conditions: - The number parameter must be a default argument. - If the default argument for number is given in...
Rules: You may NOT use the following built-in functions. sort() sum() max() min() Except for format() all string methods are banned. Except for append() and extend() all list methods are banned. You may not import any module. Make sure to test your code with a variety of inputs. Do not assume the examples in these directions are reflective of the hidden test cases. Part 3 Echo (5 Points) Write a function called echo that takes as argument a list and...
Using Java, create functions that return specific values listed below. MUST use integer only, functions, loops, conditionals. Money has to be stored as two different integers, one integer for dollars and another for cents. No use of double : String moneyToString(int d, int c); // Returns the Money as words. Ex, moneyToString(10,24) => "$10.24" void printSum(int d1, int c1, int d2, int c2); // Prints the sum of monies. Ex, printSum(10,24,3,90) => print "$14.14" int biggestMoney(int d1, int c1, int...
Write a program in Java to implement the max-priority queue using max-heap data structure. Implement the max-heap data structure using an integer array of 10 cells. (Do not use Java in-built PriorityQueue class.) [In a max-heap, the root node and the intermediate node vales are always greater than their children.] First, take 10 integer values from the user and insert them in the max-priority queue. Then print the elements of the queue. After that, delete two elements from the queue...
Suppose that A is an array whose integer elements are organized into a max-heap. Also suppose that e is an integer. Write an algorithm IS-IN-MAX-HEAP(A, e) that tests if e is an element of A. Your algorithm must not change A, and it must not make copies of A. It must avoid visiting all elements of A where possible—so it must not use linear search. You may state your answer in English, in Cormen’s pseudocode notation, or in a programming...
Must create a JFrame in JAVA that must convert both from BASE2 to BASE10 and also BASE10 to BASE2 in the same JFrame. NOTE: The results of the conversion must be displayed within the GUI - that is not in a popup or as console output.
1.This is a problem from our midterm. HOWEVER, you must use functions to solve the problem this time.(using Java please!) Write a program that prompts the user to enter two strings s1 and s2 and reports whether s2 is a substring of s1. The matching should be case-sensitive. The ONLY String class methods you are allowed to use is charAt(index) and length().