Consider the driver class below, which makes use of two other classes, Echo and
ID: 3859651 • Letter: C
Question
Consider the driver class below, which makes use of two other classes, Echo and NumberMystery:
Driver class
Echo and NumberMystery
import java.util.Scanner;
import java.io.*;
public class Echo{
private String fileName; // external file name
private Scanner scan; // Scanner object for reading from external file
public Echo(String f) throws IOException{
fileName = f;
scan = new Scanner(new FileReader(fileName));
}
public void readLines(){ // reads lines, hands each to processLine
while(scan.hasNext()){
processLine(scan.nextLine());
}
scan.close();
}
public void processLine(String line){
System.out.println(line);
}
}
import java.io.*;
public class NumberMystery extends Echo{
private int specialNum = 0;
public NumberMystery(String f) throws IOException{
super(f);
}
public void processLine(String line){
String[] items = line.split(" ");
for(String i : items){
if(i.length() > 0){
int k = Integer.parseInt(i);
if ((k > specialNum) && (k%10 == 0)) specialNum = k;
}
}
}
public void reportSpecial(){
System.out.println(specialNum);
}
}
If NumberRows.txt holds the following data:
What value does MysteryDriver line 6 (e.reportSpecial()) print?
Enter your answer in the box below.
Explanation / Answer
here It will read line by line and split them into strings and convert each stirng to its integer and check for dividiblilty of 10 and if that value is grater than the value holding in specialNum then that value is replaced with new larger value
so finally 110 is the largest number in the give file which is dividble by 10
so answer is
110