Question: 6) [12.5 marks] Read the entire input one line at a time and then output the even numbered lines (starting with the first line, line

6) [12.5 marks] Read the entire input one line at a time and then output the even numbered lines (starting with the first line, line 0) followed by the odd-numbered lines. The order even lines (and odd lines) should be the same as they appeared in the input. 7) [12.5 marks] Read the input one line at a time. At any point after reading the first 42 lines, if some line is blank (i.e., a string of length 0) then output the line that occurred 42 lines prior to that one. For example, if Line 242 is blank, then your program should output line 200. This program should be implemented so that it never stores more than 43 lines of the input at any given time. 

part 6 class is the provided code for question 6 and part 7 class is for question 7

package comp2402a1;

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.FileWriter;

import java.io.IOException;

import java.io.InputStreamReader;

import java.io.PrintWriter;

public class Part6 {

/**

* Your code goes here - see Part0 for an example

* @param r the reader to read from

* @param w the writer to write to

* @throws IOException

*/

public static void doIt(BufferedReader r, PrintWriter w) throws IOException {

// Your code goes here - see Part0 for an example

}

/**

* The driver. Open a BufferedReader and a PrintWriter, either from System.in

* and System.out or from filenames specified on the command line, then call doIt.

* @param args

*/

public static void main(String[] args) {

try {

BufferedReader r;

PrintWriter w;

if (args.length == 0) {

r = new BufferedReader(new InputStreamReader(System.in));

w = new PrintWriter(System.out);

} else if (args.length == 1) {

r = new BufferedReader(new FileReader(args[0]));

w = new PrintWriter(System.out);

} else {

r = new BufferedReader(new FileReader(args[0]));

w = new PrintWriter(new FileWriter(args[1]));

}

long start = System.nanoTime();

doIt(r, w);

w.flush();

long stop = System.nanoTime();

System.out.println("Execution time: " + 10e-9 * (stop-start));

} catch (IOException e) {

System.err.println(e);

System.exit(-1);

}

}

}

-----------------------------------

package comp2402a1;

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.FileWriter;

import java.io.IOException;

import java.io.InputStreamReader;

import java.io.PrintWriter;

public class Part7 {

/**

* Your code goes here - see Part0 for an example

* @param r the reader to read from

* @param w the writer to write to

* @throws IOException

*/

public static void doIt(BufferedReader r, PrintWriter w) throws IOException {

// Your code goes here - see Part0 for an example

}

/**

* The driver. Open a BufferedReader and a PrintWriter, either from System.in

* and System.out or from filenames specified on the command line, then call doIt.

* @param args

*/

public static void main(String[] args) {

try {

BufferedReader r;

PrintWriter w;

if (args.length == 0) {

r = new BufferedReader(new InputStreamReader(System.in));

w = new PrintWriter(System.out);

} else if (args.length == 1) {

r = new BufferedReader(new FileReader(args[0]));

w = new PrintWriter(System.out);

} else {

r = new BufferedReader(new FileReader(args[0]));

w = new PrintWriter(new FileWriter(args[1]));

}

long start = System.nanoTime();

doIt(r, w);

w.flush();

long stop = System.nanoTime();

System.out.println("Execution time: " + 10e-9 * (stop-start));

} catch (IOException e) {

System.err.println(e);

System.exit(-1);

}

}

}

JAVA

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!