Question

In: Computer Science

Using JAVA and NETBEANS Assignment Content For this assignment, you will develop "starter" code. After you...

Using JAVA and NETBEANS

Assignment Content

  1. For this assignment, you will develop "starter" code. After you finish, your code should access an existing text file that you have created, create an input stream, read the contents of the text file, sort and store the contents of the text file into an ArrayList, then write the sorted contents via an output stream to a separate output text file.

    Copy and paste the following Java™ code into a JAVA source file in NetBeans:

    import java.io.BufferedReader;

    import java.io.BufferedWriter;

    public class Datasort {

    public static void main (String [] args) {

    File fin =     // input file

    File fout =   // create an out file

    // Java FileInputStream class obtains input bytes from a file

    FileInputStream fis = new FileInputStream(fin);     

    // buffering characters so as to provide for the efficient reading of characters, arrays, and lines

    BufferedReader in = new BufferedReader(new InputStreamReader(fis));

    // declare an array in-line, ready for the sort

    String aLine;

    ArrayList<String> al = new ArrayList<String> ();

    int i = 0;

    while ((aLine = in.readLine()) != null) {

    // set the sort for values is greater than 0

    Collections.sort(al);   // sorted content to the output file

    {

    System.out.println(s);             

    }

    // close the 2 files                       

    }

    }

    Add code as indicated in the comments.

    Note: Refer to this week's Individual assignment, "Week Three Analyze Assignment," and to Ch. 8, "IO," in OCP: Oracle® Certified Professional Java® SE 8 Programmer II Study Guide.

    Run and debug your modified program in NetBeans until it satisfies the requirements described above.

Solutions

Expert Solution

If you have any doubts, please give me comment...

import java.io.*;

import java.util.*;

public class Datasort {

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

File fin = new File("input.txt"); // input file

File fout = new File("output.txt"); // create an out file

// Java FileInputStream class obtains input bytes from a file

FileInputStream fis = new FileInputStream(fin);

FileOutputStream fos = new FileOutputStream(fout);

// buffering characters so as to provide for the efficient reading of

// characters, arrays, and lines

BufferedReader in = new BufferedReader(new InputStreamReader(fis));

BufferedWriter out = new BufferedWriter(new OutputStreamWriter(fos));

// declare an array in-line, ready for the sort

String aLine;

ArrayList<String> al = new ArrayList<String>();

int i = 0;

while ((aLine = in.readLine()) != null) {

al.add(aLine);

}

// set the sort for values is greater than 0

if (al.size() > 0){

Collections.sort(al);

// sorted content to the output file

for(i=0; i<al.size(); i++)

{

out.write(al.get(i)+"\n");

}

}

// close the 2 files

out.close();

in.close();

}

}


Related Solutions

Assignment Content Resource: ****************************CODE PASTED BELOW******************************* For this assignment, you will develop Java™ code that relies...
Assignment Content Resource: ****************************CODE PASTED BELOW******************************* For this assignment, you will develop Java™ code that relies on localization to format currencies and dates. In NetBeans, copy the linked code to a file named "Startercode.java". Read through the code carefully and replace all occurrences of "___?___" with Java™ code. Note: Refer to "Working with Dates and Times" in Ch. 5, "Dates, Strings, and Localization," in OCP: Oracle® Certified Professional Java® SE 8 Programmer II Study Guide for help. Run and debug...
I am using NetBeans IDE Java for coding. I would like the code to be commented...
I am using NetBeans IDE Java for coding. I would like the code to be commented for a better understanding. 1. Implement a class Robot that simulates a robot wandering on an infinite plane. The robot is located at a point with integer coordinates and faces north, east, south, or west. Supply methods: public void turnLeft() public void turnRight() public void move() public Point getLocation() public String getDirection() The turnLeft and turnRight methods change the direction but not the location....
in Java using netbeans create a project and in it a class with a main. We...
in Java using netbeans create a project and in it a class with a main. We will be using the Scanner class to read from the user. At the top of your main class, after the package statement, paste import java.util.Scanner; Part A ☑ In your main method, paste this code. Scanner scan = new Scanner(System.in); System.out.println("What is x?"); int x = scan.nextInt(); System.out.println("What is y?"); int y = scan.nextInt(); System.out.println("What is z?"); int z = scan.nextInt(); System.out.println("What is w?");...
in Java using netbeans create a project and in it a class with a main. We...
in Java using netbeans create a project and in it a class with a main. We will be using the Scanner class to read from the user. At the top of your main class, after the package statement, paste import java.util.Scanner; Part A ☑ In your main method, paste this code. Scanner scan = new Scanner(System.in); System.out.println("What is x?"); int x = scan.nextInt(); System.out.println("What is y?"); int y = scan.nextInt(); System.out.println("What is z?"); int z = scan.nextInt(); System.out.println("What is w?");...
PLEASE CODE IN JAVA In this assignment you will write a program in that can figure...
PLEASE CODE IN JAVA In this assignment you will write a program in that can figure out a number chosen by a human user. The human user will think of a number between 1 and 100. The program will make guesses and the user will tell the program to guess higher or lower.                                                                   Requirements The purpose of the assignment is to practice writing functions. Although it would be possible to write the entire program in the main function, your...
Create a new Java project using NetBeans, giving it the name L-14. In java please Read...
Create a new Java project using NetBeans, giving it the name L-14. In java please Read and follow the instructions below, placing the code statements needed just after each instruction. Leave the instructions as given in the code. Declare and create (instantiate) an integer array called List1 that holds 10 places that have the values: 1,3,4,5,2,6,8,9,2,7. Declare and create (instantiate) integer arrays List2 and List3 that can hold 10 values. Write a method called toDisplay which will display the contents...
in netbeans using Java Create a project and a class with a main method, TestCollectors. ☑...
in netbeans using Java Create a project and a class with a main method, TestCollectors. ☑ Add new class, Collector, which has an int instance variable collected, to keep track of how many of something they collected, another available, for how many of that thing exist, and a boolean completist, which is true if we want to collect every item available, or false if we don't care about having the complete set. ☑ Add a method addToCollection. In this method,...
USING JAVA (netbeans) In your main, ask the user for an int. Do this by first...
USING JAVA (netbeans) In your main, ask the user for an int. Do this by first printing a request for the int, then creating an int x, and using the Scanner to read an int from the user and put it in x, like this: int x = scan.nextInt(); ☑ Next read in two doubles d1 and d2 from the user. This will look a lot like what you did for the int, but the scanner reads doubles using scan.nextDouble();...
USE GENERICS TO WRITE THE JAVA CODE FOR THIS ASSIGNMENT In this assignment, rewrite two of...
USE GENERICS TO WRITE THE JAVA CODE FOR THIS ASSIGNMENT In this assignment, rewrite two of the following sorting methods (Insertion Sort, Selection Sort, Quick Sort, and Merge Sort) to sort ArrayList of objects using Comaprable interface. (60 points)
For this assignment, you will be analyzing the Java™ code in the linked Week 3 Analyze...
For this assignment, you will be analyzing the Java™ code in the linked Week 3 Analyze Assignment Zip File, and predicting the results. You will also examine both the code and the output for inconsistencies and clarity. This Java™ code includes examples of for, while, and do-while loops. Carefully read through the code line by line, then answer the following questions in a Microsoft® Word document: What is the output of the program as it is written? What improvement(s) could...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT