Given the sample.txt and reference class, come up with the main class of the code so that the program will generate the sample run provided (see attached image): Sample.txt: Bieber,Justine,W,American,16 Green,Charlie,B,British,13 Concepcion,Sam,V,Filipino,17 Pempingco,Charice,A,Filipino,18 Gaga,Lady,D,American,20 Reference class: public class Person implements Comparable { private String name; private String nationality; private int age; public Person(String n, String c, int a) { name = n; nationality = c; age = a; } public int getAge() { return age; } public String toString() { return (name + "," + nationality + "," + age); } public int compareTo(Person another) { if (age == another.getAge()) return 0; else if (age < another.getAge()) return -1; else return 1; } // end of compareTo } // end of Person Please complete the code below: public class Activity{ public static void main(String[]args) { try { activity=new Activity(); // 1. Invoke the run method ____________________________; } catch(FileNotFoundException e1) { System.out.println(e1.getMessage()); } catch(NumberFormatException e2) { //2. Print the message attribute of the exception __________________________; } catch(Exception e3) { e3.printStackTrace(); } finally { System.out.println("End of Process"); } System.exit(0); } // end of main public void run() throws _____________________________ { // 3. TO DO } } // end of class
Given the sample.txt and reference class, come up with the main class of the code so that the program will generate the sample run provided (see attached image):
Sample.txt:
Bieber,Justine,W,American,16
Green,Charlie,B,British,13
Concepcion,Sam,V,Filipino,17
Pempingco,Charice,A,Filipino,18
Gaga,Lady,D,American,20
Reference class:
public class Person implements Comparable<Person> {
private String name;
private String nationality;
private int age;
public Person(String n, String c, int a) {
name = n;
nationality = c;
age = a;
}
public int getAge() {
return age;
}
public String toString() {
return (name + "," + nationality + "," + age);
}
public int compareTo(Person another) {
if (age == another.getAge())
return 0;
else if (age < another.getAge())
return -1;
else
return 1;
} // end of compareTo
} // end of Person
Please complete the code below:
public class Activity{
public static void main(String[]args) {
try {
activity=new Activity();
// 1. Invoke the run method
____________________________;
} catch(FileNotFoundException e1) {
System.out.println(e1.getMessage());
} catch(NumberFormatException e2) {
//2. Print the message attribute of the exception
__________________________;
} catch(Exception e3) {
e3.printStackTrace();
} finally {
System.out.println("End of Process");
}
System.exit(0);
} // end of main
public void run() throws _____________________________ {
// 3. TO DO
}
} // end of class
Step by step
Solved in 3 steps with 1 images